>_BeginnerCoder
Donate

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.

Task

Add a key age=20 to user and print name and age.

← Back
Next →

Enjoying this lesson? Share it 👇

Keep going with Python Foundations

Ready for more? These paid resources pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. We only recommend tools we believe are genuinely useful.