DEV Community

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

Posted on

1

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

Explica este código Python

Dificultad: Intermedio

n = [76, 24]
p = n.copy()
n.pop()
print(p, n)
Enter fullscreen mode Exit fullscreen mode
  • A. [76] [76, 24]
  • B. [76, 24] [76, 24]
  • C. [76] [76]
  • D. [76, 24] [76]

Respuesta:

👉 D. [76, 24] [76]

Al hacer p = n.copy() tanto n como p son listas completamente independientes, cualquier operación que hagamos a una no se vera reflejada en la otra.

Entonces al hacer n.pop() solo eliminamos el último item de n manteniendo a p intacta.

Cuando queremos hacer un clon de una lista esta es la manera correcta.

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

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay