-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Correct usage of "positive numbers" in FAQ section "What’s a negative index?". #140176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I added the words `signed numbers` to cover zero, positive numbers and negative numbers in the section **What’s a negative index?**.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While yes, 0 is not a positive number, I am -0 on this as I do not think this is the place to make such a distinction. It has no benefit to the explanation (it has no impact on the important bit: "0 is the first index"), and IMO, unnecessarily extends it.
index and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``. | ||
|
||
Using negative indices can be very convenient. For example ``S[:-1]`` is all of | ||
Using negative indices can be very convenient. For example ``S[:-1]`` is all of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this change.
positive numbers 0 is the first index 1 is the second index and so forth. For | ||
negative indices -1 is the last index and -2 is the penultimate (next to last) | ||
index and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``. | ||
Python sequences are indexed with signed numbers (zero, positive numbers and negative numbers). For example, 0 is the 1st index and for positive indices, 1 is the 2nd index, 2 is the 3rd index and so forth. For |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should be wrapped to 79 characters.
CC @AA-Turner, I am interested to hear your opinion on this. |
Python sequences are indexed with signed numbers (zero, positive numbers and negative numbers). For example, 0 is the 1st index and for positive indices, 1 is the 2nd index, 2 is the 3rd index and so forth. For | ||
negative indices, -1 is the last index, -2 is the penultimate (next to last) | ||
index and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that old text was too bad. But you if considered to change that - please use more common terminology. What's "signed numbers" are? Integers, right?
You could mention that for non-negative indexes it's meaning is just usual zero-based indexing of arrays. For negative indexes, the index i
is relative to the end of sequence, i.e.: len(seq) + i
is substituted.
I corrected the meaning of the words positive numbers used in the section What’s a negative index?.
In the original explanation, the words positive numbers are used to cover the numbers greater than or equal to zero but actually, zero is neither a positive number nor negative number. Positive numbers are only the numbers greater than zero.
So as the main change, I added the words signed numbers to cover 3 types of numbers zero, positive numbers and negative numbers in the section What’s a negative index?.
📚 Documentation preview 📚: https://cpython-previews--140176.org.readthedocs.build/