del
删除字典中的key或整个字典
删除key
my_dict = {'name': 'xiaoming', 'age': 10}
del my_dict['name']
print(my_dict)
结果
{'age': 10}
删除整个字典
my_dict = {'name': 'xiaoming', 'age': 10}
del my_dict
print(my_dict)
结果
报错 NameError: name 'my_dict' is not defined
删除字典中的key或整个字典
my_dict = {'name': 'xiaoming', 'age': 10}
del my_dict['name']
print(my_dict)
结果
{'age': 10}
my_dict = {'name': 'xiaoming', 'age': 10}
del my_dict
print(my_dict)
结果
报错 NameError: name 'my_dict' is not defined