Python标准库:内置函数dict(iterable, **kwarg)
Python标准库:内置函数dict(iterable, **kwarg)
本函数是从可迭代对象来创建新字典。比如一个元组组成的列表,或者一个字典对象。
例子:
#dict() #以键对方式构造字典 d1 = dict(one = 1, two = 2, a = 3) print(d1) #以映射函数方式来构造字典 d2 = dict(zip(['one', 'two', 'three'], [1, 2, 3])) print(d2) #可迭代对象方式来构造字典 d3 = dict([('one', 1), ('two', 2), ('three', 3)]) print(d3) d4 = dict(d3) print(d4)
输出结果如下:
{'a': 3, 'two': 2, 'one': 1}
{'two': 2, 'one': 1, 'three': 3}
{'two': 2, 'one': 1, 'three': 3}
{'two': 2, 'one': 1, 'three': 3}
蔡军生 QQ:9073204 深圳
相关内容
- Python标准库:内置函数classmethod(function)
- Python标准库:内置函数compile(source, filename, mode, flags=0
- Beginning Python From Novice to Professional (6) - 函数使用
- Python标准库:内置函数all(iterable)
- Python学习笔记18:标准库之多进程(multiprocessing包)
- Python学习笔记17:标准库之数学相关(之math包,random包
- Python学习笔记13:标准库之子进程(subprocess包)
- Python学习笔记12:标准库之对象序列化
- Python学习笔记11:标准库之文件管理
- Python 实现类似PHP的strip_tags函数功能,并且可以自定义
评论关闭