next()

next(it) asks an iterator for its next item; iter(x) gets an iterator from an iterable.

In more detail

Calling them by hand shows what a for loop does behind the scenes. next(it, default) returns the default instead of raising StopIteration at the end.

Example

it = iter([1, 2])
next(it), next(it)

Related terms

Taught in

References