Use in to check if a key exists:
person = {"name": "Alice", "age": 30}
print("name" in person) # True
print("height" in person) # False
Use not in for the opposite:
if "height" not in person:
print("Height unknown")
Check before accessing to avoid KeyError. Or use get() for simpler code.