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