mirror of
https://github.com/python/cpython.git
synced 2025-11-11 14:44:57 +00:00
fix minor markup error: \code{for} --> \keyword{for}
This commit is contained in:
parent
b1e5b50531
commit
e6ed33a6b3
1 changed files with 7 additions and 6 deletions
|
|
@ -4286,7 +4286,7 @@ finally the instance converted to a string using the built-in function
|
||||||
\section{Iterators\label{iterators}}
|
\section{Iterators\label{iterators}}
|
||||||
|
|
||||||
By now, you've probably noticed that most container objects can be looped
|
By now, you've probably noticed that most container objects can be looped
|
||||||
over using a \code{for} statement:
|
over using a \keyword{for} statement:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
for element in [1, 2, 3]:
|
for element in [1, 2, 3]:
|
||||||
|
|
@ -4302,11 +4302,12 @@ for line in open("myfile.txt"):
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
This style of access is clear, concise, and convenient. The use of iterators
|
This style of access is clear, concise, and convenient. The use of iterators
|
||||||
pervades and unifies Python. Behind the scenes, the \code{for} statement calls
|
pervades and unifies Python. Behind the scenes, the \keyword{for}
|
||||||
\function{iter()} on the container object. The function returns an iterator
|
statement calls \function{iter()} on the container object. The
|
||||||
object that defines the method \method{next()} which accesses elements in the
|
function returns an iterator object that defines the method
|
||||||
container one at a time. When there are no more elements, \method{next()}
|
\method{next()} which accesses elements in the container one at a
|
||||||
raises a \exception{StopIteration} exception which tells the \code{for} loop
|
time. When there are no more elements, \method{next()} raises a
|
||||||
|
\exception{StopIteration} exception which tells the \keyword{for} loop
|
||||||
to terminate. This example shows how it all works:
|
to terminate. This example shows how it all works:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue