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")
1# You can use 'in' on a dictionary to check if a key exists
2d = {"key1": 10, "key2": 23}
3"key1" in d
4# Output:
5# True