Python字典的添加,修改,删除,清空
dict1 = {'name': 'Tom', 'age': 18, 'gender': '男'}
print(dict1)
# 修改
dict1['age'] = 21
print(dict1)
# 添加
dict1['id'] = 1
print(dict1)
# 删除
del dict1['id']
print(dict1)
# del dict1 直接删除字典
# 清空
dict1.clear()
print(dict1)
dict1 = {'name': 'Tom', 'age': 18, 'gender': '男'}
print(dict1)
# 修改
dict1['age'] = 21
print(dict1)
# 添加
dict1['id'] = 1
print(dict1)
# 删除
del dict1['id']
print(dict1)
# del dict1 直接删除字典
# 清空
dict1.clear()
print(dict1)