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.

Level: intermediateTopic: Python advanced

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.