liveBook · Manning

__next__

__next__ is a Python special method that returns an iterator’s next item or raises StopIteration when no items remain.

How 2 Manning books explain it

Python Workout: 50 ten-minute exercises

__next__ is a Python special method that returns an iterator's next value and signals exhaustion when no values remain.

How it is used
Uses __next__ to implement custom iteration and explain how for loops obtain values.
How deep it goes
Explains state, advancement, exhaustion, and reusable iterator designs, while deferring broader iterator variations to exercises.
Examples
Demonstrates LoudIterator, MyEnumerate, Circle, generator expressions, and generator functions.
What you can do after
Builds custom iterators that return values, maintain position, and signal exhaustion with StopIteration.

Read how Python Workout: 50 ten-minute exercises explains __next__ →

Python Workout, Second Edition

The __next__ method is Python's special method that returns the next value from an iterator or raises StopIteration when no values remain.

How it is used
Implements the value-by-value production step underlying Python for loops and direct next() calls.
How deep it goes
Explains state storage, boundary checks, returned values, StopIteration, and separate iterator objects, but defers generator internals.
Examples
Demonstrates LoudIterator, MyEnumerate, Circle, generator expressions, and a custom range-like iterator.
What you can do after
Builds a class-based iterator that tracks progress, returns values, and terminates correctly with StopIteration.

Read how Python Workout, Second Edition explains __next__ →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.