Python : 创建字典的方法
作者:互联网
1 直接创建
dict = {‘name’:‘earth’, ‘port’:‘80’}
2 工厂方法
items=[(‘name’,‘earth’),(‘port’,‘80’)]
dict2=dict(items)
dict1=dict(([‘name’,‘earth’],[‘port’,‘80’]))
3 fromkeys()方法
dict1={}.fromkeys((‘x’,‘y’),-1)
dict={‘x’:-1,‘y’:-1}
dict2={}.fromkeys((‘x’,‘y’))
dict2={‘x’:None, ‘y’:None}
标签:fromkeys,name,dict2,Python,创建,dict,earth,80,字典 来源: https://blog.csdn.net/weixin_44523387/article/details/91977206