python中生成字典

 

1、

>>> a = {"a":111,"b":222,"c":333,"d":444}
>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> len(a)
4
>>> type(a)
<class 'dict'>

 

2、

>>> a = dict((("a",111),("b",222),("c",333),("d",444)))
>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> len(a)
4
>>> type(a)
<class 'dict'>

 

3、

>>> a = dict(a = 111, b = 222, c = 333, d = 444)
>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> len(a)
4
>>> type(a)
<class 'dict'>

 

4、

>>> a = {}
>>> a["a"] = 111
>>> a["b"] = 222
>>> a
{'a': 111, 'b': 222}
>>> len(a)
2
>>> type(a)
<class 'dict'>

 

上一篇:02-多任务-thread


下一篇:数据库_MySql高级