exception StopIteration
Raised by built-in function next()
and an iterator‘s __next__()
method to signal that there are no further items produced by the iterator.
The exception object has a single attribute value
, which is given as an argument when constructing the exception, and defaults to None
.
When a generator or coroutine function returns, a new StopIteration
instance is raised, and the value returned by the function is used as the value
parameter to the constructor of the exception.
If a generator function defined in the presence of a from __future__
import generator_stop
directive raises StopIteration
, it will be converted into a RuntimeError
(retaining the StopIteration
as the new exception’s cause).
Changed in version 3.3: Added value
attribute and the ability for generator functions to use it to return a value.
Changed in version 3.5: Introduced the RuntimeError transformation.
Please login to continue.