Python dict() 函數
Python 內置函數html
描述
dict() 函數用於建立一個字典。python
語法
dict 語法:app
class dict(**kwarg) class dict(mapping, **kwarg) class dict(iterable, **kwarg)
參數說明:函數
- **kwargs -- 關鍵字
- mapping -- 元素的容器。
- iterable -- 可迭代對象。
返回值
返回一個字典。ui
實例
如下實例展現了 dict 的使用方法:spa
>>>dict() # 建立空字典 {} >>> dict(a='a', b='b', t='t') # 傳入關鍵字 {'a': 'a', 'b': 'b', 't': 't'} >>> dict(zip(['one', 'two', 'three'], [1, 2, 3])) # 映射函數方式來構造字典 {'three': 3, 'two': 2, 'one': 1} >>> dict([('one', 1), ('two', 2), ('three', 3)]) # 可迭代對象方式來構造字典 {'three': 3, 'two': 2, 'one': 1} >>>
Python 內置函數code