Python Controleer of sleutel in woordenboek bestaat
Controleer of de sleutel in het woordenboek bestaat
Gebruik het in
trefwoord om te bepalen of een opgegeven sleutel aanwezig is in een woordenboek:
Voorbeeld
Controleer of "model" aanwezig is in het woordenboek:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
if "model" in thisdict:
print("Yes, 'model' is
one of the keys in the thisdict dictionary")