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
2 Respuestas
+ 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
0
Thank you