DEV Community

Cover image for Ibuprofeno.py💊| #108: Explica este código Python
Cristian Fernando
Cristian Fernando

Posted on • Edited on

1

Ibuprofeno.py💊| #108: Explica este código Python

Explica este código Python

Dificultad: Intermedio

person = {}
person['fname'] = 'Joe'
person['lname'] = 'Fonebone'
person['age'] = 51
person['spouse'] = 'Edna'
person['children'] = ['Ralph', 'Betty', 'Joey']
person['pets'] = {'dog': 'Fido', 'cat': 'Sox'}

print(person.get("pets").get("cat"))
Enter fullscreen mode Exit fullscreen mode

👉 A. Fido
👉 B. Sox
👉 C. SyntaxError
👉 D. TypeError


Respuesta:

👉 B. Sox

Los diccionarios pueden contener otros diccionarios en su interior. Esta sintaxis se llama diccionario anidados y para acceder a sus valores se debe concatenar métodos get() (como en este reto) o se puede usar también la sintaxis de corchete:

print(person["pets"]["cat"]) # Sox
Enter fullscreen mode Exit fullscreen mode

Nota también como creamos el diccionario, inicialmente person es un diccionario vacío y lo vamos llenando propiedad a propiedad asignado valores a diferentes claves.


Billboard image

Use Playwright to test. Use Playwright to monitor.

Join Vercel, CrowdStrike, and thousands of other teams that run end-to-end monitors on Checkly's programmable monitoring platform.

Get started now!

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay