Predict Dictionary Access
Predict Output Easy
Question
What does this code print?
Code
d = {"a": 1, "b": 2}
print(d["a"])
print(d.get("c", 0))
Hint
get() returns the default if the key is missing.
Explanation
d["a"] accesses the value for key "a", which is 1. d.get("c", 0) returns 0 because "c" is not in the dictionary and 0 is the default. Output: 1 then 0.
Related Resources
Related Lessons
- Dictionaries
Dictionary 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.