Skip to content

Commit 2f49c9d

Browse files
authored
bpo-40620: Clarify tutorial controlflow.rst range examples (GH-26919)
1 parent 74d60ea commit 2f49c9d

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
@@ -110,14 +110,14 @@ The given end point is never part of the generated sequence; ``range(10)`` gener
110110
is possible to let the range start at another number, or to specify a different
111111
increment (even negative; sometimes this is called the 'step')::
112112

113-
range(5, 10)
114-
5, 6, 7, 8, 9
113+
>>> list(range(5, 10))
114+
[5, 6, 7, 8, 9]
115115

116-
range(0, 10, 3)
117-
0, 3, 6, 9
116+
>>> list(range(0, 10, 3))
117+
[0, 3, 6, 9]
118118

119-
range(-10, -100, -30)
120-
-10, -40, -70
119+
>>> list(range(-10, -100, -30))
120+
[-10, -40, -70]
121121

122122
To iterate over the indices of a sequence, you can combine :func:`range` and
123123
:func:`len` as follows::
@@ -137,7 +137,7 @@ function, see :ref:`tut-loopidioms`.
137137

138138
A strange thing happens if you just print a range::
139139

140-
>>> print(range(10))
140+
>>> range(10)
141141
range(0, 10)
142142

143143
In many ways the object returned by :func:`range` behaves as if it is a list,
@@ -155,13 +155,7 @@ that takes an iterable is :func:`sum`::
155155
6
156156

157157
Later we will see more functions that return iterables and take iterables as
158-
arguments. Lastly, maybe you are curious about how to get a list from a range.
159-
Here is the solution::
160-
161-
>>> list(range(4))
162-
[0, 1, 2, 3]
163-
164-
In chapter :ref:`tut-structures`, we will discuss in more detail about
158+
arguments. In chapter :ref:`tut-structures`, we will discuss in more detail about
165159
:func:`list`.
166160

167161
.. _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)