Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
218e47b6
Commit
218e47b6
authored
Jun 01, 2019
by
Marco Buttu
Committed by
Raymond Hettinger
Jun 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29414: Change 'the for statement is such an iterator' in Tutorial (GH-273)
parent
36dcaab7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
Doc/tutorial/controlflow.rst
Doc/tutorial/controlflow.rst
+16
-10
No files found.
Doc/tutorial/controlflow.rst
View file @
218e47b6
...
...
@@ -139,18 +139,24 @@ 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
n *iterator*. The function :func:`list`
is another; it creates lists from iterables
::
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`
::
>>> sum(range(4)) # 0 + 1 + 2 + 3
6
>>> list(range(5))
[0, 1, 2, 3, 4]
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::
Later we will see more functions that return iterables and take iterables as argument.
>>> 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,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
``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
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`.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment