'''key 的判断''' scores={'张三':100,'李四':98,'王五':45} print('张三' in scores) print('张三' not in scores) '''删除指定的key-value对''' del scores['张三'] print(scores) '''新增字典元素''' scores['麻七']=98 #新增字典元素 print(scores) '''修改字典元素''' scores['麻七']=100 #修改元素 print(scores) '''清空字典''' scores.clear() print(scores)
E:\PycharmProjects\pythonProject\venv\Scripts\python.exe E:/PycharmProjects/pythonProject/demon1/demo5.py True False {'李四': 98, '王五': 45} {'李四': 98, '王五': 45, '麻七': 98} {'李四': 98, '王五': 45, '麻七': 100} {}