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.
Table of Contents
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: thedefaultvalue 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
StopIterationexception will be raised.
Example 1: how does next () work?
See also: Python built-in functions
4.3 ★ | 3 Vote
Read More
- Zip () function in Python
- Int () function in Python
- The function id () in Python
- The oct () function in Python
- Hex () function in Python
- The map () function in Python
- The function dir () in Python
- The function set () in Python
- Help () function in Python
- Sum () function in Python
- The slice () function in Python
- The chr () function in Python
- The pow () function in Python
- The iter () function in Python