Skip to content
Built-in Functions

next()

Get the next item from an iterator.

next(iterator, default=...)

next() moves an iterator forward by one item and returns that item.

If the iterator is empty, it raises an error unless you provide a default value.

Parameters

NameDescription
iteratorAn iterator to get an item from.
defaultOptional value returned when the iterator is finished.

Returns

The next item, or the default value.

Try it

Run it and change it
colours = iter(["red", "blue"])
first = next(colours)
print(first)

Related entries