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.
Add a key age=20 to user and print name and age.
Ready for more? These paid resources pick up where this lesson leaves off.
Project-based Python Foundations video courses — the perfect paid next step after these free lessons.
Browse on Udemy →Hand-picked Python Foundations books to master the fundamentals offline.
See on Amazon →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.