Find Mistake: Missing Key Access
Find the Mistake Easy
Question
This code raises a KeyError. What is wrong?
Code
d = {"name": "Alice"}
print(d["age"])
Hint
Check if the key exists in the dictionary.
Explanation
The key "age" is not in the dictionary. The fix is to use d.get("age") (returns None) or d.get("age", "unknown") (returns a default) instead of d["age"].
Related Resources
Related Lessons
- Dictionaries
Safe key access.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.