Skip to content
dreamcode
dreamcode
Back to map
Slicing · Lesson 24 of 44
+15 XP on finish
PYTHON INTERMEDIATE

Slicing sequences

Slicing extracts a portion of a list or string using `[start:stop:step]`. Omitted values default to the beginning, end, or a step of 1.

How it reads
nums[1:4] gets index 1 up to (but not including) index 4
nums[::-1] reverses the sequence
Cloud tip: Negative indices count from the end of the list, e.g., nums[-1] is the last item.
main.py
PYTHON
real Python, runs in your browser
CONSOLE
- run your code to see output -