from builtins.py
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] = vdict(**kwargs) -> new dictionary initialized with the name=value pairsin the keyword argument list. For example: dict(one=1, two=2)使用关键字参数列表中的“名称=值”对初始化的新字典。 例如:dict(one = 1,two = 2)# (copied from class doc)"""pass
示例:
以下实例展示了 dict 的使用方法:
>>>dict() # 创建空字典{}>>> dict(a='a', b='b', t='t')# 传入关键字{'a': 'a', 'b': 'b', 't': 't'}>>> dict(zip(['one', 'two', 'three'], [1, 2, 3])) # 映射函数方式来构造字典{'three': 3, 'two': 2, 'one': 1} >>> dict([('one', 1), ('two', 2), ('three', 3)]) # 可迭代对象方式来构造字典{'three': 3, 'two': 2, 'one': 1}>>>
参考文章1:Python dict() 函数
参考文章2:python zip类 (将对象中对应的元素打包成若干元组,返回由这些若干元组组成的对象,节省内存)