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
[doc] Range tutorial shorthand could be made clearer #84800
Comments
I found https://docs.python.org/3.7/tutorial/controlflow.html#the-range-function section 4.3 confusing. The range() Function shows the following example: >>> for i in range(5):
... print(i)
...
0
1
2
3
4 [some instructional text] range(5, 10)
5, 6, 7, 8, 9
range(0, 10, 3)
0, 3, 6, 9
range(-10, -100, -30)
-10, -40, -70 This appears to be an instruction to type, for example: leading to a perceived bug when I type at the prompt:
>>> range(5, 10)
and receive the response
range(5, 10) I ultimately figured out that the example is a shorthand to substitute >>> for i in range(5, 10):
... print(i)
...
5
6
7
8
9 It would be less confusing if the example instead read: ---------------------------- Substituting "range(5, 10)" for "range(5)" results in (one number per line) Substituting "range(0, 10, 3)" results in and substituting "range(-10, -100, -30)" results in --------------------------- such that it is clear that the statements are not meant to be taken as literal stand-alone entries to be typed at the prompt but are instead substitutions. |
This block is the same in 3.9 and 3.8. My first though is this block is a holdover from 2.7, where range returned list. But looking at what is written previously, I think your interpretation is correct -- and agree that something other that code and corresponding output in a code block is confusing. So this might better be a list than a code block. Cheryl, do you have an idea of what might be better? |
Another alternative is to make the example *be* interactive. >>> list(range(5, 10))
[5, 6, 7, 8, 9]
>>> list(range(0, 10, 3))
[0, 3, 6, 9]
>>> list(range(-10, -100, -30))
[-10, -40, -70] |
Thank you Jack! |
range
examples #26919range
examples (GH-26919) #26927range
examples (GH-26919) #26928Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: