Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

readme.md

KeyError: 'age'

Occurs when accessing a dictionary key that does not exist.

reproduce.py

data = {"name": "John"}
print(data["age"])

Error message

KeyError: 'age'

fix.py

data = {"name": "John"}
print(data.get("age"))

Reflection

Use .get() to safely access dictionary keys that might not exist.