If a class defines an
method, that method is called:
Whenever the built-in
function is applied to an instance of the class.
In any situation where the instance is iterated
over, such as when it appears as the controlling
iterable of a
The calling sequence is:
def __iter__(self): ...
The return value must be an iterator. An iterator is any
object that has a
.next() method that returns
the next value in the sequence, or raises
StopIteration when the sequence is exhausted. For
more information, see Section 24.2, “Iterators: Values that can produce a sequence of