LESSON 9
Dictionaries
Learning objective: Store key-value data with dictionaries.
Understand
Dictionaries map keys to values.
A dictionary uses curly braces and key: value pairs. You access values by key rather than position. Dictionaries are perfect for structured records like a user profile.
Analogy: A dictionary is like a real dictionary: look up a word (key) to get its meaning (value).
See It in Action
A user dictionary:
user = {"name": "Sam", "age": 20}
print(user["name"]) # SamHow it works:
user['name'] looks up the value stored under the key 'name'.Try It Yourself
- Create a dictionary describing a book.
- Print one value by its key.
- Add a new key-value pair.
Quick Quiz
How do you access a dictionary value?
Challenge
Model a person as a dictionary with at least three keys.
Success condition: Your dictionary stores and prints values by key.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →