python创建字典的两种方法

>>> dict1 = {'name': 'earth', 'port': 80}
>>> dict2 = {}
>>> dict1,dict2
({'name': 'earth', 'port': 80}, {})
>>> 

工厂方法创建字典

>>> dict3 = dict((['x',1],['y',2]))     
>>> dict3
{'y': 2, 'x': 1}
>>> 

猜你喜欢

转载自blog.51cto.com/yht1990/2144323