Dict Access
Predict Output Easy
Question
What does this code print?
Code
d = {"a": 1, "b": 2}
print(d.get("c", 0))
Hint
get returns the default 0 for missing key "c".
Explanation
d.get("c", 0) returns 0 because "c" is not in the dictionary and the default is 0. Without the default, get returns None.
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.