From 713281ccb51f1569a9b17c3e0c01bc7f1f4be3c0 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 24 Feb 2017 16:59:38 +0100 Subject: [PATCH 1/7] bpo-29414: Change 'the for statement is such an iterator' in Tutorial --- Doc/tutorial/controlflow.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 81a28a6e53257f..facec9491a1f3b 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -142,12 +142,13 @@ the list, thus saving space. We say such an object is *iterable*, that is, suitable as a target for functions and constructs that expect something from which they can obtain successive items until the supply is exhausted. We have seen that -the :keyword:`for` statement is such an *iterator*. The function :func:`list` -is another; it creates lists from iterables:: +the :keyword:`for` statement is such a construct, while an example of function +that takes an iterable is :func:`sum()`: +.. doctest:: - >>> list(range(5)) - [0, 1, 2, 3, 4] + >>> sum(range(4)) # 0 + 1 + 2 + 3 + 6 Later we will see more functions that return iterables and take iterables as argument. From 841c1c4f19e997e64ad0ede07c085183dfe2c73d Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sat, 25 Feb 2017 16:23:43 +0100 Subject: [PATCH 2/7] bpo-29414: fix a typo not related to the issue. --- Doc/tutorial/controlflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index facec9491a1f3b..80d4faad65b798 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -150,7 +150,7 @@ that takes an iterable is :func:`sum()`: >>> sum(range(4)) # 0 + 1 + 2 + 3 6 -Later we will see more functions that return iterables and take iterables as argument. +Later we will see more functions that return iterables and take iterables as arguments. .. _tut-break: From 4836f72ec6e06c5270578da5afc5b4853dd119a1 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sat, 25 Feb 2017 16:34:58 +0100 Subject: [PATCH 3/7] bpo-29414: Add the 'iterable' reference to the glossary --- Doc/tutorial/controlflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 80d4faad65b798..a2eda62b9f673a 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -139,7 +139,7 @@ but in fact it isn't. It is an object which returns the successive items of the desired sequence when you iterate over it, but it doesn't really make the list, thus saving space. -We say such an object is *iterable*, that is, suitable as a target for +We say such an object is :term:`iterable`, that is, suitable as a target for functions and constructs that expect something from which they can obtain successive items until the supply is exhausted. We have seen that the :keyword:`for` statement is such a construct, while an example of function From c34b0913f6dc96c08a667e6314d99e47134865a8 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Mon, 27 Feb 2017 16:11:07 +0100 Subject: [PATCH 4/7] bpo-29414: :func:`sum()` -> :func:`sum` --- Doc/tutorial/controlflow.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index a2eda62b9f673a..79afa63882a638 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -143,9 +143,7 @@ We say such an object is :term:`iterable`, that is, suitable as a target for functions and constructs that expect something from which they can obtain successive items until the supply is exhausted. We have seen that the :keyword:`for` statement is such a construct, while an example of function -that takes an iterable is :func:`sum()`: - -.. doctest:: +that takes an iterable is :func:`sum`: >>> sum(range(4)) # 0 + 1 + 2 + 3 6 From 4506cd93779ee1eb0b5b37960c6ce9d325a4a37a Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Mon, 27 Feb 2017 19:01:55 +0100 Subject: [PATCH 5/7] bpo-29414: Introduce the example using :: instead of : --- Doc/tutorial/controlflow.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 79afa63882a638..ee96fb41aeaf5e 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -143,12 +143,13 @@ We say such an object is :term:`iterable`, that is, suitable as a target for functions and constructs that expect something from which they can obtain successive items until the supply is exhausted. We have seen that the :keyword:`for` statement is such a construct, while an example of function -that takes an iterable is :func:`sum`: +that takes an iterable is :func:`sum`:: >>> sum(range(4)) # 0 + 1 + 2 + 3 6 -Later we will see more functions that return iterables and take iterables as arguments. +Later we will see more functions that return iterables and take iterables as +arguments. .. _tut-break: From d1b823892442357c351ba4aca4d03b3edbdd9ca9 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Mon, 27 Feb 2017 23:51:43 +0100 Subject: [PATCH 6/7] bpo-29414: add range to list example. --- Doc/tutorial/controlflow.rst | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index ee96fb41aeaf5e..482cd8484ada7f 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -141,7 +141,7 @@ the list, thus saving space. We say such an object is :term:`iterable`, that is, suitable as a target for functions and constructs that expect something from which they can -obtain successive items until the supply is exhausted. We have seen that +obtain successive items until the supply is exhausted. We have seen that the :keyword:`for` statement is such a construct, while an example of function that takes an iterable is :func:`sum`:: @@ -149,8 +149,14 @@ that takes an iterable is :func:`sum`:: 6 Later we will see more functions that return iterables and take iterables as -arguments. +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 +:func:`list`. .. _tut-break: @@ -161,7 +167,7 @@ The :keyword:`break` statement, like in C, breaks out of the innermost enclosing :keyword:`for` or :keyword:`while` loop. Loop statements may have an :keyword:`!else` clause; it is executed when the loop -terminates through exhaustion of the list (with :keyword:`for`) or when the +terminates through exhaustion of the iterable (with :keyword:`for`) or when the condition becomes false (with :keyword:`while`), but not when the loop is terminated by a :keyword:`break` statement. This is exemplified by the following loop, which searches for prime numbers:: @@ -188,8 +194,13 @@ following loop, which searches for prime numbers:: the :keyword:`for` loop, **not** the :keyword:`if` statement.) When used with a loop, the ``else`` clause has more in common with the +<<<<<<< HEAD ``else`` clause of a :keyword:`try` statement than it does that of :keyword:`if` statements: a :keyword:`!try` statement's ``else`` clause runs +======= +``else`` clause of a :keyword:`try` statement than it does with that of +:keyword:`if` statements: a :keyword:`try` statement's ``else`` clause runs +>>>>>>> bpo-29414: add range to list example. when no exception occurs, and a loop's ``else`` clause runs when no ``break`` occurs. For more on the :keyword:`!try` statement and exceptions, see :ref:`tut-handling`. From 71b689322cb1d15ebfaa99a885ac5412db655251 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 1 Jun 2019 13:44:49 -0700 Subject: [PATCH 7/7] Resolve merge conflict --- Doc/tutorial/controlflow.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 482cd8484ada7f..79111f8518d9bb 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -194,13 +194,8 @@ following loop, which searches for prime numbers:: the :keyword:`for` loop, **not** the :keyword:`if` statement.) When used with a loop, the ``else`` clause has more in common with the -<<<<<<< HEAD -``else`` clause of a :keyword:`try` statement than it does that of -:keyword:`if` statements: a :keyword:`!try` statement's ``else`` clause runs -======= ``else`` clause of a :keyword:`try` statement than it does with that of :keyword:`if` statements: a :keyword:`try` statement's ``else`` clause runs ->>>>>>> bpo-29414: add range to list example. when no exception occurs, and a loop's ``else`` clause runs when no ``break`` occurs. For more on the :keyword:`!try` statement and exceptions, see :ref:`tut-handling`.