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