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
Update 25 November 2019
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
Maybe you are interested
How to Communicate Well With People from Other Cultures What does the 'super slow' 7680fps movie recording feature on the Mate 30 Pro do? Hitman Sniper famous game is being free on iOS and Android How to create slow motion videos on Android? 7 signs that you still haven't earned enough money to spend 5 things should be a little more and 5 things should be invested more