-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Open
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
Description
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 instep
increments until it passesstop
, never includingstop
.
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
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
Projects
Status
Todo