Starlit Daily

📚 › Python: the friendliest first language

6. Slicing lists

Este artículo se traducirá automáticamente. Por ahora se muestra en inglés.

A slice takes part of a list: items[1:3] gives items at positions 1 and 2, because the end is not included. items[:2] starts at the beginning, and items[-1] is the last item.

Slicing never changes the original list.

Ver ejemplo

letters = ["a", "b", "c", "d"]
print(letters[1:3])
print(letters[-1])

✍️ Ahora te toca

From [10, 20, 30, 40, 50], print the middle three items as a list.

← Volver al curso