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 missing key in a dictionary.

Reproduce

data = {
    "name": "john"
}

age = data["age"]
print(age)

Error Message

KeyError: 'age'

Fix

data = {
    "name": "john"
}

age = data.get("age", 0)
print(age)

Reflection

Assumed the key existed without checking.