DEV Community

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

Posted on

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

Explica este código Python

Dificultad: Fácil

cl = [2, 3, 1]
print(cl.pop(2))
Enter fullscreen mode Exit fullscreen mode
  • A. [3, 1]
  • B. 2
  • C. 1
  • D. [2, 3]

Respuesta:

👉 C. 1

El método pop() de las listas elimina y obtiene el último valor de una lista (sino le pasamos ningún parámetro) o elimina y obtiene el valor de la lista que nosotros queramos si le pasamos un índice.

En este caso decir cl.pop(2) es lo mismo que decir cl.pop(), ambos apuntan al último elemento de la lista.

La lista quedará [2, 3] pero cuando imprimimos el valor borrado print(cl.pop(2)) entonces el resultado será 1.

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