Starlit Daily

📚 › Python: the friendliest first language

11. Dictionaries

A dictionary stores key-value pairs inside braces: {"city": "Dhaka"}. Get a value by its key: person["city"]. Use .get("key") to avoid errors when a key may be missing.

Dictionaries are ideal for records such as a student's name and marks.

Show example

student = {"name": "Nadia", "marks": 88}
print(student["name"], student.get("grade", "n/a"))

✍️ Your turn

Create a dictionary with country set to Bangladesh, then print its value.

← Back to course