Python 检查字典中是否存在键
检查字典中是否存在键
要确定字典中是否存在指定的键,请使用 in
关键字
示例
检查字典中是否存在“model”
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
if "model" in thisdict
print("是的,'model' 是 thisdict 字典中的一个键")
自己动手试一试 »
要确定字典中是否存在指定的键,请使用 in
关键字
检查字典中是否存在“model”
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
if "model" in thisdict
print("是的,'model' 是 thisdict 字典中的一个键")
自己动手试一试 »
如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com
如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com