python how to check if key in dict code example
Example 1: python how to check if a dictionary key exists
if word in data:
return data[word]
else:
return "The word doesn't exist. Please double check it."
Example 2: contanskey in python
d = {
"a": 1,
"b": 2
}
# To check if key is there in the dictionary
if "a" in d:
print("Found")