📜  python 从 dict 中删除键 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:06.718000             🧑  作者: Mango

代码示例6
dict = {'an':30, 'example':18}
#1 Del
del dict['an']

#2 Pop (returns the value deleted, but can also be used alone)
#You can optionally set a default return value in case key is not found
dict.pop('example') #deletes example and returns 18
dict.pop('test', 'Key not found') #returns 'Key not found'