Python3.5(六) 字典

class dict(object):
    """
    dict() -> new empty dictionary
    dict(mapping) -> new dictionary initialized from a mapping object‘s
        (key, value) pairs
    dict(iterable) -> new dictionary initialized as if via:
        d = {}
        for k, v in iterable:
            d[k] = v
    dict(**kwargs) -> new dictionary initialized with the name=value pairs
        in the keyword argument list.  For example:  dict(one=1, two=2)
    """

    def clear(self): # real signature unknown; restored from __doc__
        """ 清除内容 """
        """ D.clear() -> None.  Remove all items from D. """
        pass

    def copy(self): # real signature unknown; restored from __doc__
        """ 浅拷贝 """
        """ D.copy() -> a shallow copy of D """
        pass

    @staticmethod # known case
    def fromkeys(S, v=None): # real signature unknown; restored from __doc__
        """
        dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
        v defaults to None.
        """
        pass

    def get(self, k, d=None): # real signature unknown; restored from __doc__
        """ 根据key获取值,d是默认值 """
        """ D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None. """
        pass

    def has_key(self, k): # real signature unknown; restored from __doc__
        """ 是否有key """
        """ D.has_key(k) -> True if D has a key k, else False """
        return False

    def items(self): # real signature unknown; restored from __doc__
        """ 所有项的列表形式 """
        """ D.items() -> list of D‘s (key, value) pairs, as 2-tuples """
        return []

    def iteritems(self): # real signature unknown; restored from __doc__
        """ 项可迭代 """
        """ D.iteritems() -> an iterator over the (key, value) items of D """
        pass

    def iterkeys(self): # real signature unknown; restored from __doc__
        """ key可迭代 """
        """ D.iterkeys() -> an iterator over the keys of D """
        pass

    def itervalues(self): # real signature unknown; restored from __doc__
        """ value可迭代 """
        """ D.itervalues() -> an iterator over the values of D """
        pass

    def keys(self): # real signature unknown; restored from __doc__
        """ 所有的key列表 """
        """ D.keys() -> list of D‘s keys """
        return []

    def pop(self, k, d=None): # real signature unknown; restored from __doc__
        """ 获取并在字典中移除 """
        """
        D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
        If key is not found, d is returned if given, otherwise KeyError is raised
        """
        pass

    def popitem(self): # real signature unknown; restored from __doc__
        """ 获取并在字典中移除 """
        """
        D.popitem() -> (k, v), remove and return some (key, value) pair as a
        2-tuple; but raise KeyError if D is empty.
        """
        pass

    def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
        """ 如果key不存在,则创建,如果存在,则返回已存在的值且不修改 """
        """ D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """
        pass

    def update(self, E=None, **F): # known special case of dict.update
        """ 更新
            {‘name‘:‘alex‘, ‘age‘: 18000}
            [(‘name‘,‘sbsbsb‘),]
        """
        """
        D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
        If E present and has a .keys() method, does:     for k in E: D[k] = E[k]
        If E present and lacks .keys() method, does:     for (k, v) in E: D[k] = v
        In either case, this is followed by: for k in F: D[k] = F[k]
        """
        pass

    def values(self): # real signature unknown; restored from __doc__
        """ 所有的值 """
        """ D.values() -> list of D‘s values """
        return []

    def viewitems(self): # real signature unknown; restored from __doc__
        """ 所有项,只是将内容保存至view对象中 """
        """ D.viewitems() -> a set-like object providing a view on D‘s items """
        pass

    def viewkeys(self): # real signature unknown; restored from __doc__
        """ D.viewkeys() -> a set-like object providing a view on D‘s keys """
        pass

    def viewvalues(self): # real signature unknown; restored from __doc__
        """ D.viewvalues() -> an object providing a view on D‘s values """
        pass

    def __cmp__(self, y): # real signature unknown; restored from __doc__
        """ x.__cmp__(y) <==> cmp(x,y) """
        pass

    def __contains__(self, k): # real signature unknown; restored from __doc__
        """ D.__contains__(k) -> True if D has a key k, else False """
        return False

    def __delitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__delitem__(y) <==> del x[y] """
        pass

    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ x.__eq__(y) <==> x==y """
        pass

    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__(‘name‘) <==> x.name """
        pass

    def __getitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__getitem__(y) <==> x[y] """
        pass

    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ x.__ge__(y) <==> x>=y """
        pass

    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ x.__gt__(y) <==> x>y """
        pass

    def __init__(self, seq=None, **kwargs): # known special case of dict.__init__
        """
        dict() -> new empty dictionary
        dict(mapping) -> new dictionary initialized from a mapping object‘s
            (key, value) pairs
        dict(iterable) -> new dictionary initialized as if via:
            d = {}
            for k, v in iterable:
                d[k] = v
        dict(**kwargs) -> new dictionary initialized with the name=value pairs
            in the keyword argument list.  For example:  dict(one=1, two=2)
        # (copied from class doc)
        """
        pass

    def __iter__(self): # real signature unknown; restored from __doc__
        """ x.__iter__() <==> iter(x) """
        pass

    def __len__(self): # real signature unknown; restored from __doc__
        """ x.__len__() <==> len(x) """
        pass

    def __le__(self, y): # real signature unknown; restored from __doc__
        """ x.__le__(y) <==> x<=y """
        pass

    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ x.__lt__(y) <==> x<y """
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ x.__ne__(y) <==> x!=y """
        pass

    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass

    def __setitem__(self, i, y): # real signature unknown; restored from __doc__
        """ x.__setitem__(i, y) <==> x[i]=y """
        pass

    def __sizeof__(self): # real signature unknown; restored from __doc__
        """ D.__sizeof__() -> size of D in memory, in bytes """
        pass

    __hash__ = None

dict
时间: 2024-12-18 17:52:55

Python3.5(六) 字典的相关文章

python3学习之字典

字典: 简单字典: dic = {1:'a',2:'b',3:'c'} 嵌套字典:字典中可包含元组.列表.字典 dic = {1:'a',2:'b',3:'c',4:{1:'a',2:'b',3:'c'},5:[1,2,3],6:(5,6)} dic.clear() 清空 dic.fromkeys(iterable, value=None, /)    不明白有什么用 dic.items()  显示字典中的所有键值对 dic.pop(k[,d])  弹出   k代表key,必须指定,返回被弹出的

Python3基础 创建字典 空字典的几种方式 示例

镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.------------------------------------------ code: shengHao=['地藏王','释迦摩尼'] book=['地藏菩萨本愿经','金刚经'] #不用字典时, print(shengHao[shengHao.index('地藏王')],'-->',book[shengHao.index('地藏王')]) # () 元组 # [

python3.6 创建字典三法

这里献丑给出 python 3.6 创建字典变量的三法 其一:阳春白雪法:直接声明  mydic = {"name":"徐晓冬","age":"38"} 其二:调用dict()函数,以表达式的方式创建 mydict2 = dict(name="徐晓冬",age="38") 其三:调用dick()函数合并两个列表,其中一个列表为键,另一个列表为值 mykeys = ["name&

Python3匿名函数字典排序、生成式与生成器、装饰器简介

1. 参数匿名函数字典排序 函数的参数: 参数类型:我们经常在看别人的代码中,经常出现def(*args,**kwargs)这样的表现形式; *args tuple(1,) **kwargs dict{"k" : "v"} fun(*args,**keargs) fun(1,2,3,4,5,a=10,b=40) 匿名函数: 匿名函数的定义:顾名思义就是没有名字的函数,那为什么要设立匿名函数,他有什么作用?lambda函数是一种快速付款定义机器智能单行的最小函数,可以

Python3教程之字典

字典(dictionary)是Python中另一个非常有用的内置数据类型.列表是有序的对象集合,字典是无序的对象集合.两者之间的区别在于:字典当中的元素是通过键来存取的,而不是通过偏移存取.字典是一种映射类型,字典用"{ }"标识,它是一个无序的键(key) : 值(value)对集合.键(key)必须使用不可变类型且在同一个字典中,键(key)必须是唯一的. 原文地址:https://www.cnblogs.com/Chiang2018/p/10093469.html

【Python】入门学习六 字典及其相关操作

字典由一系列键-值对组成,每个键都与一个值相关联,通过键我们可以访问其对应的值.这些值可以是Python中的任意对象类型,键必须是不可变类型,包括数字.字符串.元组,但不能使用列表. 1.创建字典 字典用放在花括号{}中的一系列键值对表示,键和值之间用冒号隔开,每个元素之间用逗号隔开 dic_0 = {'name' : 'zhangsan', 'age' : '22'} 2.访问字典 字典名['要访问的键名'],例如上例中 student_name = dic_0['name'] 3.添加字典内

python3之利用字典和列表实现城市多级菜单

利用字典和列表实现城市多级菜单 1 #coding:utf-8 2 #利用字典和列表实现城市多级菜单 3 addrIndex = {"1":"北京","2":"上海","3":"南京","4":"福建"} 4 addrDict = {"北京":["东城区","西城区","大兴区&

循序渐进Python3(六) -- 面向对象

Python 面向对象 什么是面向对象编程? 面向对象编程是一种程序设计范式 对现实世界建立对象模型 把程序看作不同对象的相互调用 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.下面我们将详细介绍Python的面向对象编程. 如果你以前没有接触过面向对象的编程语言,那你可能需要先了解一些面向对象语言的一些基本特征,在头脑里头形成一个基本的面向对象的概念,这样有助于你更容易的学习Python的面向对象编程. 接下来我们先来简单的了解下面向

2018-05-14 代码考古-Python3官方教程字典例程

知乎原链 Data Structures中的第一个例程: >>> tel = {'jack': 4098, 'sape': 4139} >>> tel['guido'] = 4127 >>> tel {'sape': 4139, 'guido': 4127, 'jack': 4098} >>> tel['jack'] 4098 >>> del tel['sape'] >>> tel['irv'] =