Why is "keyerror: 'key_name'" showing in my python code?
Example:
dict_data = {"name": "John"}
print(dict_data["age"])
The error means the specified key isn't present in the dictionary.
Solution:
print(dict_data.get("age", "Age not found"))
Example: Solution:Why is "keyerror: 'key_name'" showing in my python code?
The error means the specified key isn't present in the dictionary.
dict_data = {"name": "John"}
print(dict_data["age"])
print(dict_data.get("age", "Age not found"))