增:
In [1]: info = {"name":"xiaoyafei","age":"18"} In [2]: info["addr"] = "henan" In [3]: info Out[3]: {‘addr‘: ‘henan‘, ‘name‘: ‘xiaoyafei‘, ‘age‘: ‘18‘}
删:
In [4]: info Out[4]: {‘addr‘: ‘henan‘, ‘name‘: ‘xiaoyafei‘, ‘age‘: ‘18‘} In [5]: del info["age"] In [6]: info Out[6]: {‘addr‘: ‘henan‘, ‘name‘: ‘xiaoyafei‘}
改:
In [7]: info Out[7]: {‘addr‘: ‘henan‘, ‘name‘: ‘xiaoyafei‘} In [8]: info["name"] = "xiaobaba" #如果key存在则修改,不存在则是添加 In [9]: info Out[9]: {‘addr‘: ‘henan‘, ‘name‘: ‘xiaobaba‘}
查:
In [10]: info Out[10]: {‘addr‘: ‘henan‘, ‘name‘: ‘xiaobaba‘} In [11]: info.get("addr") Out[11]: ‘henan‘ In [12]: info.get("age")