Python: method creates a dictionary

1 created directly

= {dict 'name': 'Earth', 'Port': '80'}
2 factory methods

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}

Guess you like

Origin blog.csdn.net/weixin_44523387/article/details/91977206