可迭代对象 ping iter 作用 实例 构造 ppi blog
作用:dict() 函数用于创建一个字典。返回一个字典。
语法:
- class dict(**kwarg)
- class dict(mapping, **kwarg)
- class dict(iterable, **kwarg)
参数说明:
实例:
- 1 >>> dict()#创建空字典2 {}
- 3 >>> dict(a = 'a', b = 'b', t = 't')#传入关键字4 {'a': 'a',
- 'b': 'b',
- 't': 't'
- }
- 5 >>> dict(zip(['one', 'two', 'three'], [1, 2, 3]))#映射函数方式来构造字典6 {'three': 3,
- 'two': 2,
- 'one': 1
- }
- 7 >>> dict([('one', 1), ('two', 2), ('three', 3)])#可迭代对象方式来构造字典8 {'three': 3,
- 'two': 2,
- 'one': 1
- }
- 9 >>>
Python 函数 dict()
来源: http://www.bubuko.com/infodetail-2106763.html