According to https://stackoverflow.com/a/40637053, we need __next__()
to actually progress through a sequence of things, and __iter__()
to reset the starting point (for iteration):
The "iterable interface" in python consists of two methods __next__()
and __iter__()
. The __next__()
function is the most important, as it defines the iterator behavior - that is, the function determines what value should be returned next. The __iter__()
method is used to reset the starting point of the iteration. Often, you will find that __iter__()
can just return self when __init__()
is used to set the starting point.
The documentation should be the go-to for understanding this, https://docs.python.org/3/glossary.html#term-iterator:
Iterators are required to have an __iter__()
method that returns the iterator object itself so every iterator is also iterable and may be used in most places where other iterables are accepted. One notable exception is code which attempts multiple iteration passes.
But I don't find that particularly illuminating.
I'd also check to see how Python itself uses __iter__()
, https://github.com/python/cpython/search?q=__iter__.