Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dd8c42

Browse files
committed
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.
1 parent 03ec6d5 commit 2dd8c42

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Doc/lib/libstdtypes.tex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ \subsection{Iterator Types \label{typeiter}}
395395
was added in Python 2.3; in Python 2.2, various iterators are
396396
broken according to this rule.)
397397

398+
Python's generators provide a convenient way to implement the
399+
iterator protocol. If a container object's \method{__iter__()}
400+
method is implemented as a generator, it will automatically
401+
return an iterator object (technically, a generator object)
402+
supplying the \method{__iter__()} and \method{next()} methods.
403+
398404

399405
\subsection{Sequence Types \label{typesseq}}
400406

0 commit comments

Comments
 (0)