Question about the __iter__() function

Doing this lesson: previous slide

I would like a further explanation as to why iter() must return self?

class Iterator: def __iter__(self): self.count = 0 return self

I think that’s because we want objects/instances of the class to be both iterables and iterators.
__iter__ should return the iterator and if the class/object is the iterator, so it should return itself.

1 Like