Python · Stage 5 – Grouping Data · Lesson 30 of 50

Dictionaries and Key-Value Pairs

Look up values using meaningful keys instead of numbered positions.

user = {"name": "Maya", "age": 12}
Line-by-line explanation
  1. Curly braces create the dictionary.
  2. "name" is a key and "Maya" is its value.
  3. A colon connects each key to its value.
  4. A comma separates pairs.
print(user["name"])
Line-by-line explanation
  1. user is the dictionary.
  2. ["name"] looks up that key.
  3. The output is Maya.