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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 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