python 字典的‘增、删、改、查’
用 ipython 运行情况如下:
#新建字典
In [1]: infos = {'name':'dongge','age':18}
In [2]: infos
Out[2]: {'name': 'dongge', 'age': 18}
#增加key:QQ
In [3]: infos['QQ'] = 3333333
In [4]: infos
Out[4]: {'name': 'dongge', 'age': 18, 'QQ': 3333333}
#删除key:age
In [5]: del infos['age']
In [6]: infos
Out[6]: {'name': 'dongge', 'QQ': 3333333}
#修改
In [7]: infos['QQ']= 12312414
In [8]: infos
Out[8]: {'name': 'dongge', 'QQ': 12312414}
#查询:
In [9]: infos.get('age')#无返回值
In [10]: infos.get('QQ')
Out[10]: 12312414