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
>>>

 

你可能感兴趣的:(python,字典的基本操作)