英文文档
class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)
Create a new dictionary. The dict object is the dictionary class. See dict and Mapping Types — dict for documentation about this class.
For other containers see the built-in list, set, and tuple classes, as well as the collections module.
dict()
1、字典类的构造函数。
2、不传入任何参数时,返回空字典。
>>> dict()
{}
3、可以传入键值对创建字典。
>>> dict(a=1)
{'a': 1}
>>> dict(a=1, b=2)
{'a': 1, 'b': 2}
4、可以传入映射函数创建字典。
>>> dict(zip(['a', 'b'], [1, 2]))
{'a': 1, 'b': 2}
5、可以传入可迭代对象创建字典。
>>> dict((('a', 1), ('b', 2)))
{'a': 1, 'b': 2}
小结
希望通过上面的操作能帮助大家。如果你有什么好的意见,建议,或者有不同的看法,希望你留言和我进行交流、讨论。
欢迎关注微信公众号,访问更多精彩:数据之魅。
如需转载,请联系授权,谢谢合作。