PYTHON INTERMEDIATEChapter 6 · Comprehensions and data tools
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.
Worked example
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.


