hi,各位大牛,新手上路,對工廠函數不太理解,dict()怎么用?
Python中的dict()怎么用?
jeck貓
2018-07-16 08:18:11
TA貢獻1887條經驗 獲得超5個贊
dict(one=1, two=2)
dict({'one': 1, 'two': 2})
dict(zip(('one', 'two'), (1, 2)))
dict([['two', 2], ['one', 1]])
TA貢獻1828條經驗 獲得超6個贊
內置的文檔很詳細了
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] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
舉報