让我们看一些例子:
字典()
a=dict()
---> {}
字典(** kwargs)
a=dict(one=1, two=2, three=3)
---> {'one':1,'two':2,'three':3}
字典(映射,** kwargs)
a=dict({'one':1, 'two':2, 'three':3})
---> { '一':1, '二':2 '3':3}
a=dict({'one':1, 'two':2, 'three':3}, four=4,five=5,six=6)
---> {{ 'one':1,'two':2,'3':3,'four':4,'five':5,'six':6}
dict(iterable,** kwarg)
a=dict([('one',1),('two',2),('three',3)])
---> { '一':1, '二':2 '3':3}
a=dict((['one',1],['two',2],['three',3]))
---> { '一':1, '二':2 '3':3}
a=dict([('one',1),('two',2),('three',3)], four=4,five=5,six=6)
---> { '一':1, '二':2,“三':3,'four':4,'five':5,'six':6}
a=dict((['one',1],['two',2],['three',3]),four=4,five=5,six=6)
--->''''':','two':2,'three':3 , '四':4 '5':5 '6':6}
注:
调用字典(可迭代,** kwarg)函数等于--->
d={}
a=[('one',1),('two',2),('three',3)]
for k,v in a:
d[k]=v
print(d)
“目前只有一个标准映射类型,词典。 “我认为这里的文档很清楚(https://docs.python.org/2/library/stdtypes.html#mapping-types-dict) –
@ Mr.E - 是的,OP将问题链接到问题中。他引用的片段来自该部分。 – TigerhawkT3
@ TigerhawkT3意外地只发送链接:P。更正了它 –