DEV Community

Cristian Fernando
Cristian Fernando

Posted on

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

Explica este código Python

Dificultad: Fácil

my_list = [1,2,3,4,5]
res = my_list[1:4:2]
print(res)
Enter fullscreen mode Exit fullscreen mode
  • A. [1 ,2]
  • B. [2, 4]
  • C. [1, 4]
  • D. [2, 5]

Respuesta:

👉 B. [2, 4]

Cuando nos encontramos con una sintaxis de slicing donde tenemos 3 índices es importante recordar que: [inicio : final : salto], donde salto son las posiciones de la lista que tomaremos en cuenta.

En nuestro ejemplo si tuvieramos my_list[1:4] regresariamos [2,3,4,5] pero si añadimos el salto my_list[1:4:2] entones solo tomaremos [2,4].

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more