Dictionaries in Python
Dictionaries are one of the most useful and flexible data structures in Python. They store data as key-value pairs – like a real dictionary where you look up a word (key) to find its definition (value).
Dictionaries are mutable, unordered (order is preserved from Python 3.7+), and keys must be unique and immutable (strings, numbers, tuples).
They’re perfect for representing real-world objects: a person with name/age, a product with price/stock, or settings with options.
Creating a Dictionary
Use curly braces {} with key: value pairs separated by commas.
Accessing Values
Use square brackets with the key, or .get() method (safer – returns None if key missing).
Adding and Updating Items
Just assign a value to a key – creates if missing, updates if exists.
Removing Items
Use del, pop(), or clear().
Looping Through Dictionaries
Loop over keys (default), values, or items.
Nested Dictionaries
Dictionaries can contain other dictionaries – great for complex data.
Quick Quiz
Hemos revisado y comprobado los materiales, pero aún pueden existir errores. El contenido se ofrece únicamente con fines educativos, así que úsalo bajo tu propia responsabilidad y verifica con otras fuentes si es necesario.
✨ Pregunta a Lara — tu compañera de estudio con IA
Desbloquea soporte de aprendizaje personalizado. Lara puede explicar lecciones, resumir temas y responder tus preguntas — disponible desde el plan Go y superiores.
Lara te ayuda a aprender más rápido — exclusivo para los miembros ReadyTools Go, Plus y Max.

