Python参考手册
Python dict() 函数
Python dict() 函数
Python dict() 函数
Python 内置函数描述
dict() 函数用于创建一个字典。
语法
dict 语法:
class dict(**kwarg) class dict(mapping, **kwarg) class dict(iterable, **kwarg)
参数说明:
- **kwargs -- 关键字
- mapping -- 元素的容器。
- iterable -- 可迭代对象。
返回值
返回一个字典。
实例
以下实例展示了 dict 的使用方法:
>>>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 dict() 函数 |
---|
Python 是一种面向对象的解释型计算机程序设计语言,由荷兰人 Guido van Rossum 于1989年发明,第一个公开发行版发行于1991年。 Python 是纯粹的自由软件, 源代码和解释器 CPython 遵循 GPL 协议。Python 语法简洁清晰,特色之一是强制用空白符( white space )作为语句缩进。
主页 | https://www.python.org/ |
源码 | https://github.com/python/cpython |
版本 | 2.7 |
发布版本 | 2.7.13 |