
Nov. 29, 2021
4:02 a.m.
On Sun, Nov 28, 2021, 8:59 PM Steven D'Aprano
To be an iterator, your object needs:
1. a `__next__` method which returns the next value; 2. and an `__iter__` method which returns self.
That's not quite right. An iterator only needs .__next__(), and an iterable only needs .__iter__(). Returning self is a convenient, and probably the most common, way of creating an object that is both. But exceptions exist, and remain iterators and/or iterables.