mirror of https://github.com/python/cpython
SF bug #696777: How to make a class iterable using a member generator.
* Added a note that a container class can implement the iterator protocol by defining its __iter__() method as a generator.
This commit is contained in:
parent
03ec6d538a
commit
2dd8c42638
|
@ -395,6 +395,12 @@ do not obey this property are deemed broken. (This constraint
|
|||
was added in Python 2.3; in Python 2.2, various iterators are
|
||||
broken according to this rule.)
|
||||
|
||||
Python's generators provide a convenient way to implement the
|
||||
iterator protocol. If a container object's \method{__iter__()}
|
||||
method is implemented as a generator, it will automatically
|
||||
return an iterator object (technically, a generator object)
|
||||
supplying the \method{__iter__()} and \method{next()} methods.
|
||||
|
||||
|
||||
\subsection{Sequence Types \label{typesseq}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue