[Python-checkins] bpo-40620: Clarify tutorial controlflow.rst ``range`` examples (GH-26919) (GH-26928)

iritkatriel webhook-mailer at python.org
Sun Jun 27 15:52:36 EDT 2021


https://github.com/python/cpython/commit/1acd1e63850d179383fcb638dcefee4c66b3ca4e
commit: 1acd1e63850d179383fcb638dcefee4c66b3ca4e
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2021-06-27T20:52:32+01:00
summary:

bpo-40620: Clarify tutorial controlflow.rst ``range`` examples (GH-26919) (GH-26928)

(cherry picked from commit 2f49c9debc2efe010c757be3bdbd6493f1ebc5f6)

Co-authored-by: jdevries3133 <58614260+jdevries3133 at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Documentation/2021-06-26-17-41-06.bpo-40620.PAYDrB.rst
M Doc/tutorial/controlflow.rst

diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
index 44417134a92ad..129ab21cc48ce 100644
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -104,14 +104,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::
@@ -131,7 +131,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,
@@ -149,13 +149,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:
diff --git a/Misc/NEWS.d/next/Documentation/2021-06-26-17-41-06.bpo-40620.PAYDrB.rst b/Misc/NEWS.d/next/Documentation/2021-06-26-17-41-06.bpo-40620.PAYDrB.rst
new file mode 100644
index 0000000000000..52b451b492640
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2021-06-26-17-41-06.bpo-40620.PAYDrB.rst
@@ -0,0 +1,2 @@
+Convert examples in tutorial controlflow.rst section 4.3 to be interpreter-demo
+style.



More information about the Python-checkins mailing list