Python Prüfen Sie, ob der Schlüssel im Wörterbuch vorhanden ist
Überprüfen Sie, ob der Schlüssel im Wörterbuch vorhanden ist
Um festzustellen, ob ein bestimmter Schlüssel in einem Wörterbuch vorhanden ist, verwenden Sie das in
Schlüsselwort:
Beispiel
Überprüfen Sie, ob "Modell" im Wörterbuch vorhanden ist:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
if "model" in thisdict:
print("Yes, 'model' is
one of the keys in the thisdict dictionary")