Dict Get Method
Multiple Choice Easy
Question
What does {}.get("missing") return?
Hint
get returns None for missing keys.
Explanation
{}.get("missing") returns None because the key does not exist. Unlike d["missing"] which raises KeyError, get() returns None (or a specified default) for missing keys. Use d.get("key", "default") to specify a custom default. This is the safe way to access dictionaries when keys might be missing.
Related Resources
Related Lessons
- Dictionaries
Learn Python dictionaries.
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.