Skip to content

Commit 1acd1e6

Browse files
bpo-40620: Clarify tutorial controlflow.rst range examples (GH-26919) (GH-26928)
(cherry picked from commit 2f49c9d) Co-authored-by: jdevries3133 <[email protected]>
1 parent b2a5dcd commit 1acd1e6

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

Doc/tutorial/controlflow.rst

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ The given end point is never part of the generated sequence; ``range(10)`` gener
104104
is possible to let the range start at another number, or to specify a different
105105
increment (even negative; sometimes this is called the 'step')::
106106

107-
range(5, 10)
108-
5, 6, 7, 8, 9
107+
>>> list(range(5, 10))
108+
[5, 6, 7, 8, 9]
109109

110-
range(0, 10, 3)
111-
0, 3, 6, 9
110+
>>> list(range(0, 10, 3))
111+
[0, 3, 6, 9]
112112

113-
range(-10, -100, -30)
114-
-10, -40, -70
113+
>>> list(range(-10, -100, -30))
114+
[-10, -40, -70]
115115

116116
To iterate over the indices of a sequence, you can combine :func:`range` and
117117
:func:`len` as follows::
@@ -131,7 +131,7 @@ function, see :ref:`tut-loopidioms`.
131131

132132
A strange thing happens if you just print a range::
133133

134-
>>> print(range(10))
134+
>>> range(10)
135135
range(0, 10)
136136

137137
In many ways the object returned by :func:`range` behaves as if it is a list,
@@ -149,13 +149,7 @@ that takes an iterable is :func:`sum`::
149149
6
150150

151151
Later we will see more functions that return iterables and take iterables as
152-
arguments. Lastly, maybe you are curious about how to get a list from a range.
153-
Here is the solution::
154-
155-
>>> list(range(4))
156-
[0, 1, 2, 3]
157-
158-
In chapter :ref:`tut-structures`, we will discuss in more detail about
152+
arguments. In chapter :ref:`tut-structures`, we will discuss in more detail about
159153
:func:`list`.
160154

161155
.. _tut-break:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Convert examples in tutorial controlflow.rst section 4.3 to be interpreter-demo
2+
style.

0 commit comments

Comments
 (0)