Next / Previous / Contents / TCC Help System / NM Tech homepage

26.3.17. __iter__(): Create an iterator

If a class defines an .__iter__() method, that method is called:

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 values”.