Answers for "how to check only if a key exist"

22

python check if key exists

# You can use 'in' on a dictionary to check if a key exists
d = {"key1": 10, "key2": 23}
"key1" in d
# Output:
# True
Posted by: Guest on February-19-2020
1

Dictionary Check Key Exist

hh = {"a":3, "b":4, "c":5}

# check if a key exists

print("b" in hh)
# True
Posted by: Guest on December-10-2021

Code answers related to "how to check only if a key exist"

Python Answers by Framework

Browse Popular Code Answers by Language