python之字典

                                       字典包含的信息量大!

 

 

1:定义字典:

 >>> zidian={‘付超‘:‘01‘,‘张小亮‘:‘02‘,‘李小毛‘:‘03‘}
>>>

2:字典的组成 key:value,key:value

3:查看value

>>> zidian.values()
dict_values([‘02‘, ‘01‘, ‘03‘])

4:字典的添加:

>>> zidian[‘添加‘]=‘123‘
>>> zidian
{‘张小亮‘: ‘02‘, ‘付超‘: ‘01‘, ‘李小毛‘: ‘03‘, ‘添加‘: ‘123‘}
>>>
5:字典的删除

>>> zidian
{‘张小亮‘: ‘02‘, ‘付超‘: ‘01‘, ‘李小毛‘: ‘03‘, ‘添加‘: ‘123‘}
>>> zidian.popitem()
(‘张小亮‘, ‘02‘)
>>>

>>> zidian
{‘付超‘: ‘666‘, ‘李小毛‘: ‘03‘, ‘添加‘: ‘123‘}
>>> del zidian[‘添加‘]
>>> zidian
{‘付超‘: ‘666‘, ‘李小毛‘: ‘03‘}
>>>

6:字典的修改

>>> zidian[‘付超‘]=‘666‘
>>> zidian
{‘付超‘: ‘666‘, ‘李小毛‘: ‘03‘, ‘添加‘: ‘123‘}
>>>

7:字典的查找

>>> zidian
{‘付超‘: ‘666‘, ‘李小毛‘: ‘03‘}
>>> ‘付超‘ in zidian
True
>>>

 

本文出自 “积少成多” 博客,请务必保留此出处http://9399369.blog.51cto.com/9389369/1605361

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。