Python Part-17(Classes and iterator in python), about __iter__ and __next__ methods in class

Опубликовано: 27 Сентябрь 2024
на канале: Varteta Learning Platform
4,273
71

Iterator in python
Need to implement the _iter_ and _next_ methods
for loop in python can iterate through an instance of a class with the above two methods implemented.
StopIteration exception handled by python only.
StopIteration just indicates that iteration is over and it simply need to exit gracefully and no more iterations needed.
_init_ method as usual has been implemented