The next () function in Python
The next () function in Python returns the next element in the iterator. You can add a default value to return if iterable is already the last element.
Continuing with the topic of built-in functions in Python, the article will introduce you to the next () function with syntax, usage as well as specific examples. Invites you to read the track.
The next () function in Python returns the next element in the iterator. You can add a default value to return if iterable is already the last element.
The syntax of the next () function in Python:
next(iterator, default)
Parameters of the next () function
The next () function has 2 parameters:
iterator
: iterable object.default
: thedefault
value will be returned if iterable is the last element.
Return value from next ()
- The next () function returns the next element in the iterator
- If the iterator runs out, the function returns the default value
- If the iterator expires without a default value, the
StopIteration
exception will be raised.
Example 1: how does next () work?
See also: Python built-in functions
4.3 ★ | 3 Vote
You should read it
- The map () function in Python
- The function set () in Python
- Max () function in Python
- The oct () function in Python
- The pow () function in Python
- The slice () function in Python
- Min () function in Python
- The function id () in Python
- The reversed () function in Python
- The range () function in Python
- Sum () function in Python
- The ord () function in Python