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"])  # Sam
How it works: user['name'] looks up the value stored under the key 'name'.

Try It Yourself

  1. Create a dictionary describing a book.
  2. Print one value by its key.
  3. 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.