Python 检查字典中是否存在键
检查字典中是否存在键
要确定字典中是否存在指定的键,请使用 in
关键字:
实例
检查字典中是否存在"模型":
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
if "model" in thisdict:
print("Yes, 'model' is
one of the keys in the thisdict dictionary")
亲自试一试 »