×

python · level 2 · unit 1 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A finds a value by its name, not its place.

A list finds things by position: item 0, item 1, item 2. A dictionary finds things by name, like a café menu where you look up tea and read its price. Each name is a , and each key points to one value.

Write a dictionary in curly brackets. Each pair is a key, a colon, then its value, with commas between the pairs. To look a value up, put its key in square brackets: prices["tea"].

Keys are unique, so the menu cannot list tea twice. Ask for a key that is not there, like prices["cake"], and Python stops with a .

prices = {"tea": 1.5, "coffee": 2.2, "toast": 1.8}
print(prices["coffee"])
print(prices)

Printing a whole dictionary shows every pair, in the order you added them.