summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-06-27 19:51:16 (GMT)
committerGitHub <noreply@github.com>2021-06-27 19:51:16 (GMT)
commitaeb63392e74976b4289b38f32f1d6e7ff2e0a712 (patch)
treead08166ae7a0f90d6432c4f79c09e8bac18514bb /Doc/tutorial
parentc95cdf2dae185b1241c0b1e07635dc632267e37e (diff)
downloadcpython-aeb63392e74976b4289b38f32f1d6e7ff2e0a712.zip
cpython-aeb63392e74976b4289b38f32f1d6e7ff2e0a712.tar.gz
cpython-aeb63392e74976b4289b38f32f1d6e7ff2e0a712.tar.bz2
bpo-40620: Clarify tutorial controlflow.rst ``range`` examples (GH-26919) (GH-26927)
(cherry picked from commit 2f49c9debc2efe010c757be3bdbd6493f1ebc5f6) Co-authored-by: jdevries3133 <58614260+jdevries3133@users.noreply.github.com>
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/controlflow.rst22
1 files changed, 8 insertions, 14 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
index ee2c3e5..494a795 100644
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -110,14 +110,14 @@ The given end point is never part of the generated sequence; ``range(10)`` gener
is possible to let the range start at another number, or to specify a different
increment (even negative; sometimes this is called the 'step')::
- range(5, 10)
- 5, 6, 7, 8, 9
+ >>> list(range(5, 10))
+ [5, 6, 7, 8, 9]
- range(0, 10, 3)
- 0, 3, 6, 9
+ >>> list(range(0, 10, 3))
+ [0, 3, 6, 9]
- range(-10, -100, -30)
- -10, -40, -70
+ >>> list(range(-10, -100, -30))
+ [-10, -40, -70]
To iterate over the indices of a sequence, you can combine :func:`range` and
:func:`len` as follows::
@@ -137,7 +137,7 @@ function, see :ref:`tut-loopidioms`.
A strange thing happens if you just print a range::
- >>> print(range(10))
+ >>> range(10)
range(0, 10)
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`::
6
Later we will see more functions that return iterables and take iterables as
-arguments. Lastly, maybe you are curious about how to get a list from a range.
-Here is the solution::
-
- >>> list(range(4))
- [0, 1, 2, 3]
-
-In chapter :ref:`tut-structures`, we will discuss in more detail about
+arguments. In chapter :ref:`tut-structures`, we will discuss in more detail about
:func:`list`.
.. _tut-break: