According
to https://docs.python.org/3/glossary.html#term-iterator and 
https://docs.python.org/3/library/stdtypes.html#typeiter,
 iterators must implement the __iter__ method.

On Sun, 2021-11-28 at 22:02 -0500, David Mertz, Ph.D. wrote:
> 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/

_______________________________________________
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/GIDOVVCH262MTKZKVFY7FNXJTR5EBM75/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to