Python: next() function
next() function
The next() function is used to get the next item in an iterator.
Version:
(Python 3.2.5)
Syntax:
next(iterator[, default])
Parameter:
Name | Description | Required / Optional |
---|---|---|
iterator | An iterable object. | Required |
default | This value is returned if the iterator is exhausted (no items left). | Optional |
Return value:
Returns the next item of the iterator.
Example: Python next() function
items = [7, 15, 'Python']
# converting list to iterator
itemsIterator = iter(items)
print(itemsIterator)
# Output: 7
print(next(itemsIterator))
# Output: 15
print(next(itemsIterator))
# Output: 'Python'
print(next(itemsIterator))
Output:
<list_iterator object at 0x7f8b758a8470> 7 15 Python
Pictorial Presentation:
Pictorial Presentation:
Python Code Editor:
Previous: min()
Next: object()
Test your Python skills with w3resource's quiz
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python/built-in-function/next.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics