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