Starlit Daily

📚 › Python: the friendliest first language

11. Dictionaries

Este artículo se traducirá automáticamente. Por ahora se muestra en inglés.

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.

Ver ejemplo

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

✍️ Ahora te toca

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

← Volver al curso