DEV Community

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

Posted on

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

Explica este código Python

Dificultad: Intermedio

r = [20, 40, 60, 80]
r[1:4] = []
print(r)
Enter fullscreen mode Exit fullscreen mode
  • A. [20, []]
  • B. [20]
  • C. [20, [], 60, 80]
  • D. Error

Respuesta:

👉 B. [20]

Cuando hacemos un slicing de listas procedemos a eliminar todos los items que estén dentro del intervalo del slicing, en nuestro caso los items correspondientes entre el índice 1 a 4 (sin contar el 4) o en otras palabras, todos los items menos el primero.

Al igual el sclicing a una lista vacía no significa que agreguemos la lista, sino que borramos los elementos.

Solo nos quedaría [20].

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

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay