The Iterator ProtocolPremium
An iterator has __iter__ and __next__ and raises StopIteration when finished. for loops call these for you. Writing your own class lets you control iteration.
This is a Premium lesson
All the basic lessons are free. Advanced and in-depth lessons, with every example, exercise and quiz, are included with a Premium subscription.
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.