0

What is the purpose of __iter__?

Hai guys can any one tell me what is the purpose of iter in this program and what is the behind process when I print i values in this program https://code.sololearn.com/c9t8iTaGTTAI/?ref=app

16th Feb 2021, 10:56 AM
P.B.V.Lalith Kumar
P.B.V.Lalith Kumar - avatar
2 Antworten
+ 2
The purpose of __iter__ is to return an iterator object. You have to consider the difference between iterator and iterable : - iterator : implements both __iter__ and __next__. In this case, __iter__ returns itself - iterable : implements only __iter__. In this case, __iter__ returns an associated iterator. For instance : - range_iterator is an iterator - range is an iterable that returns a range_iterator object
16th Feb 2021, 12:08 PM
Th├ęophile
Th├ęophile - avatar
0
Thank you
16th Feb 2021, 12:14 PM
P.B.V.Lalith Kumar
P.B.V.Lalith Kumar - avatar