computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

📒

🎓

⏱ 25 min

Free

Dictionaries: Labels & Values

Store information with labels using key–value pairs — perfect for game characters and contacts.

🎯 What you will learn

  • Create dictionaries with { }
  • Look up values by key
  • Add, change and loop through items

👋 Let’s get started!

A real dictionary matches words to meanings. A Python dictionary matches KEYS to VALUES — like a character card: name → “Zara”, health → 100. 📒

🪜 Step by step

1. 📒 Make one

Use curly brackets with key: value pairs.

hero = {"name": "Zara", "health": 100, "power": "flight"}
print(hero["name"])
2. ✏️ Change & add

Assign to a key to change or add it.

hero["health"] = 80
hero["level"] = 2
print(hero)
3. 🔁 Loop through

items() gives you each key and value.

for key, value in hero.items():
    print(key, "→", value)

🧪 Try it!

Change the code and press ▶ Run to see what happens. You can’t break anything!

Pet shop prices

prices = {"goldfish": 5, "hamster": 15, "parrot": 60}
for pet, cost in prices.items():
    print(pet, "costs $" + str(cost))
print("Total for all:", sum(prices.values()))

Update a score board

board = {"Ana": 3, "Ben": 5}
board["Ana"] = board["Ana"] + 4
print(board["Ana"])

📖 Key words

Tap a card to flip it over!

Dictionary
Key–value pairs in { } 📒
Key
The label you look up 🔑
Value
The information stored 🎁

🏆 Challenge

Look up and print the capital of Japan.

Challenge

capitals = {"France": "Paris", "Japan": "Tokyo", "Kenya": "Nairobi"}

Knowledge Check Quiz

  1. What prints?
  2. What brackets make a dictionary?
  3. What do you use to look something up?
← Previous lesson
Next lesson →