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
| Name | Description |
|---|---|
| iterator | An iterator to get an item from. |
| default | Optional 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)