A slice selects positions from start toward stop, excluding stop, at the chosen step.
Try different slice boundaries
Choose the boundaries. Follow the selected positions.
A slice visits positions toward its stop boundary. The stop position is excluded; reversing the step changes the direction.
0C-7
1A-6
2N-5
3T-4
4E-3
5E-2
6N-1
s[1:4]→"ANT"
Interactive model of Python slicing over Unicode code points. A visible character may contain several code points. Blank bounds are omitted, which differs from explicitly using -1 with a negative step.
text[start:stop:step]
Example
s = "CANTEEN"
print(s[1:4], s[-3:], s[::2], s[::-1])
print(repr(s[99:]))
Result
ANT EEN CNEN NEETNAC
''
Watch for: Out-of-range bounds are clipped. Step zero raises ValueError. stop-start is not a general slice-length formula.