首页>>帮助中心>>香港云服务器python中为什么没有dict函数

香港云服务器python中为什么没有dict函数

2023/6/3 449次

香港云服务器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}

>>>

一诺网络香港免备案专区,提供「香港增强云服务器」和「香港特惠云服务器」两种类型的高可用弹性计算服务,搭载新一代英特尔®至强®铂金处理器,接入CN2低延时高速回国带宽线路,网络访问顺滑、流畅。机房网络架构采用了BGP协议的解决方案可提供多线路互联融合网络,使得不同网络运营商线路的用户都能通过最佳路由实现快速访问。香港云服务器低至29元/月,购买链接:https://www.enuoidc.com/vps.html?typeid=2