BeginnerCoder

Lesson 8 — Dictionaries

Key and value pairs

A dictionary stores values under named keys, like a real dictionary maps a word to its meaning. Read or set a value with square brackets and its key: user["name"].

Why it matters: dicts are perfect for describing one thing with many properties — a user with a name, age and email.

Tip: use user.get("age") instead of user["age"] to avoid an error when the key might be missing.

Want it another way?
Task

Add a key age with value 20 to user, then print the name and the age on separate lines.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.