关于python:如果键存在,则删除字典项

方法1:最不好,用get方法判断是否存在key,会遗漏:mydict[key] = 0

if mydict.get('key'):
    del mydict[key]

方法2:

if key in mydict:
    del mydict[key]

方法3:

 mydict.pop("key", None)

参考自:

关于python:如果键存在,则删除字典项

原文地址:https://www.cnblogs.com/hailin2018/p/14967328.html