python字典的使用之增删改查
定义个字典
dic = {“id”: 1001, “name”: “张三”, “age”: 21}
print(dic)
增
dic[“school”] = “北京大学”
print(“增加后”, dic)
删
del dic[“school”]
print(“删除后”, dic)
改
dic[“id”] = 1002
print(“修改后”, dic)
查
print(“查找”, dic.get(“id”))
结果为
{‘id’: 1001, ‘name’: ‘张三’, ‘age’: 21}
增加后 {‘
原创
2021-07-21 08:34:51 ·
152 阅读 ·
0 评论