Creating Our Own Iterators

Let's find out how we can make our own iterators.

Occasionally we will want to create our own custom iterators. Python makes this very easy to do. All we need to do is implement the __iter__ and __next__ methods in our class.

Creating an iterator for string of letters

Let’s create an iterator that can iterate over a string of letters:

Get hands-on with 1400+ tech skills courses.