讓我們看一些例子:
字典()
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。更正了它 –