我想在更新密钥的值之前测试字典中是否存在密钥.我写了以下代码:
if 'key1' in dict.keys(): print "blah" else: print "boo"
我认为这不是完成这项任务的最佳方式.有没有更好的方法来测试字典中的密钥?
python dictionary
dictionary ×1
python ×1