A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3schools.com/python/ref_func_next.asp below:

Website Navigation


Python next() Function

Python next() Function

❮ Built-in Functions

Example

Create an iterator, and print the items one by one:

mylist = iter(["apple", "banana", "cherry"])
x = next(mylist)
print(x)
x = next(mylist)
print(x)
x = next(mylist)
print(x)

Try it Yourself » Definition and Usage

The next() function returns the next item in an iterator.

You can add a default return value, to return if the iterator has reached to its end.

Syntax Parameter Values Parameter Description iterator Required. An iterator object (e.g. a list). default Optional. A default value to return if the iterator has reached to its end. More Examples Example

Return a default value when the iterator has reached to its end:

mylist = iter(["apple", "banana", "cherry"])
x = next(mylist, "orange")
print(x)
x = next(mylist, "orange")
print(x)
x = next(mylist, "orange")
print(x)
x = next(mylist, "orange")
print(x)

Try it Yourself »

❮ Built-in Functions

Track your progress - it's free!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4