Creating Your Own Iterator
Learn to build your own iterator in this lesson.
We'll cover the following...
Just out of interest, we will create a couple of iterators of our own. In fact, you will probably never need to do this, as it is almost always better to use generators instead, so the rest of the chapter is pretty much optional and for background information only.
This section assumes you know the basics of creating Python classes.
An iterator is just a class that implements a __next__
method and an __iter__
method. Notice that these functions have double ...