Python Check if Key Exists in Dictionary


Check if Key Exists in Dictionary

To determine if a specified key is present in a dictionary use the in keyword:

Example

Check if "model" is present in the dictionary:

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
if "model" in thisdict:
  print("Yes, 'model' is one of the keys in the thisdict dictionary")
Try it Yourself »


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.