Bug report
Bug description:
Negative/reverse slicing (_variable[_one:_two:-1]) is easy to misinterpret using only the two‑argument “indices between characters” model from the tutorial.
Example:
_variable = [1, 2, 3, 4]
print(_variable[2:0:-1])
Expected from two‑arg mental model: [2, 1]
Actual: [3, 2] — because:
- Stop index is always excluded, even when
step is negative.
- Traversal starts at
start and moves in step increments until it passes stop, never including stop.
The tutorial’s diagram is correct for step=1 but does not cover step at all, so readers extending that model to negative steps will predict the wrong result.
Proposed doc improvement: keep current explanation for two‑argument slices, but add a short note or link to the full slicing definition in the language reference showing how negative steps work, with a concrete example like [2:0:-1] → [3, 2]. This would prevent the confusion without overloading beginners.
CPython versions tested on:
3.15
Operating systems tested on:
No response
Linked PRs
Bug report
Bug description:
Negative/reverse slicing (
_variable[_one:_two:-1]) is easy to misinterpret using only the two‑argument “indices between characters” model from the tutorial.Example:
Expected from two‑arg mental model:
[2, 1]Actual:
[3, 2]— because:stepis negative.startand moves instepincrements until it passesstop, never includingstop.The tutorial’s diagram is correct for
step=1but does not coverstepat all, so readers extending that model to negative steps will predict the wrong result.Proposed doc improvement: keep current explanation for two‑argument slices, but add a short note or link to the full slicing definition in the language reference showing how negative steps work, with a concrete example like
[2:0:-1] → [3, 2]. This would prevent the confusion without overloading beginners.CPython versions tested on:
3.15
Operating systems tested on:
No response
Linked PRs