怎么删除字典里的某一项?
请问怎么删除字典里的某一项?? d = {"A": 1,"B": 2, "C": 3}d
{'A': 1, 'B': 2, 'C': 3}
d.pop("B")
2
d
{'A': 1, 'C': 3} 用
del 字典[键]
例子:
a = {'a': 1, 'b': 2, 'c': 3}
del a['c']
print(a) # {'a': 1, 'b': 2} x_dict = {1:"one",2:"two"}
x_dict
del x_dict#删除操作
x_dict
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
x_dict
KeyError: 2 兄弟,给个好评!谢谢!!!
页:
[1]