python中为什么没有dict函数

804
2021/2/13 14:42:14
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

python中为什么没有dict函数

python中是存在dict函数的,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}

>>>



辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: Python模块subprocess详解