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: 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
You've just finished reading the article "The next () function in Python" edited by the TipsMake team. You can save the-next-function-in-python.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.