1d = {"key1": 10, "key2": 23}
2
3if "key1" in d:
4 print("this will execute")
5
6if "nonexistent key" in d:
7 print("this will not")
1dict = { "How":1,"you":2,"like":3,"this":4}
2key = "this"
3if key in dict.keys():
4 print("present")
5 print("value =",dict[key])
6else:
7 print("Not present")