To understand StopIteration
Exception, you need to understand how iterators work in Python.
- Iterator is an object that holds values which can be iterated upon.
- It uses the
__next__()
method to move to the next value in the iterator. - When the
__next__()
method tries to move to the next value, but there are no new values, aStopIteration
Exception is raised.