Dictionaries
Lesson 15 of 20 · Py.Micro
Store values under keys: look up by name instead of position.
prices["latte"] finds the value by its key. Keys are unique; asking for a missing one is a KeyError.
Check yourself
What does d.get("x", 0) return if "x" is missing?
Do it in the browser: a real Python tool, a short mission and instant feedback. No install.
Start this lesson — free