DEV Community

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

Posted on

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

Explica este código Python

Dificultad: Intermedio

def f(value, values):
    v = 1
    values[0] = 44

t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])
Enter fullscreen mode Exit fullscreen mode
  • A. 1 1
  • B. 1 44
  • C. 3 1
  • D. 3 44

Respuesta:

👉 D. 3 44

Cuando llamamos a la función f lo hacemos con los argumentos f(t, v), donde t=3 y no se modifica en el cuerpo de la función, luego tenemos la lista v = [1, 2, 3] que llega a la función como el argumento values modificando el primer item de la función dentro de la función values[0] = 44.

Cuando llamamos a la impresión print(t, v[0]), t=3 por que nunca modificamos ese valor y el nuevo primer item de la lista es 44, por lo tanto el resultado final sería 3 44

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

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