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. >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/FWRNYVLPJV7SZD5E2M5LP2GYECKBONPG/ Code of Conduct: http://python.org/psf/codeofconduct/