Python字典

字典

字典是由键-值(key-value)对构成的映射数据类型
通过键取值,不支持下标操作
>>> adict = {'host':'earth'}  #create dict
>>> adict['port'] = 80        #add to dict
>>> adict
{'host': 'earth', 'port': 80}
>>> adict.keys()
['host', 'port']
>>> adict['host']
'earth'
>>> for key in adict:
...     print key,adict[key]
... 
host earth
port 80

>>> 'host' in adict
True
>>> 'earth' in adict
False

 

posted @ 2017-03-15 09:27  Time.catcher  阅读(166)  评论(0编辑  收藏  举报