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

19.3.14. __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 sequence, or raises StopIteration when the sequence is exhausted. For more information, see Section 17.2, “Iterators: Values that can produce a sequence of values”.