This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Misinformation when showing how slices work in The Tutorial
Type: Stage: resolved
Components: Documentation Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, issuefinder, r.david.murray, steven.daprano
Priority: normal Keywords:

Created on 2016-12-19 21:19 by issuefinder, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg283649 - (view) Author: (issuefinder) Date: 2016-12-19 21:19
In this page:
https://docs.python.org/3/tutorial/introduction.html#strings

When showing how slices work:
+---+---+---+---+---+---+
 | P | y | t | h | o | n |
 +---+---+---+---+---+---+
 0   1   2   3   4   5   6
-6  -5  -4  -3  -2  -1

The accurate matrix is:

+---+---+---+---+---+---+
 | P | y | t | h | o | n |
 +---+---+---+---+---+---+
 0   1   2   3   4   5   6
 0  -6  -5  -4  -3  -2  -1
msg283652 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-12-19 21:55
If your version was correct, 'python'[-2:] would produce 'n', which is not what it produces.  Perhaps you being confused by the fact that the diagram is pointing the indexes *between* the characters?  That's the point of the mnemonic and I find it very useful to think of it that way, myself.
msg283655 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-12-19 23:37
You haven't given any reason to explain why you think the existing docs are wrong, nor any reason why you think your version is better. Just stating that the docs give "misinformation" is not good enough.

By your matrix, 'Python'[0:-1] should take a slice starting from the left of 'P' and ending at the *right* of 'n', returning 'Python' unchanged. According to the original, documented matrix, 'Python'[0:-1] takes a slice starting at the left of 'P' and ending at the *left* of 'n', returning 'Pytho'. without the n, which is what actually does happen.

You should also consider the slice 'Python'[-6:-5] according to the documented matrix (returns 'P') and your matrix (returns 'y').
msg283877 - (view) Author: (issuefinder) Date: 2016-12-23 13:08
You seem to be right.
Sorry about the incovenience.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73204
2016-12-23 13:08:33issuefindersetmessages: + msg283877
2016-12-19 23:37:31steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg283655

resolution: not a bug
stage: resolved
2016-12-19 21:55:01r.david.murraysetnosy: + r.david.murray
messages: + msg283652
2016-12-19 21:19:44issuefindercreate