AI engineering glossary · Python advanced
What is stopIteration?
StopIteration: The exception an iterator raises when it has no more items. A for loop catches it silently to end the loop, and generators raise it automatically when their function body finishes.
StopIteration: an example
Calling next() on an exhausted iterator raises StopIteration, which is how for knows to stop.
Related terms
More Python advanced terms
Where you learn it
StopIteration is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.