Dictionaries
A dictionary maps keys to values. Read with square brackets or .get() which returns None instead of failing when a key is missing.
Example
user = {"name": "Ada", "age": 21}
print(user["name"])
print(user.get("city", "unknown"))
user["city"] = "Lagos"
print(user)Result
Ada
unknown
{'name': 'Ada', 'age': 21, 'city': 'Lagos'}Exercise
Read the age.
user = {"age": 21} print(user[])
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.