THE WORLD'S LARGEST WEB DEVELOPER SITE

Python iter() Function

❮ Built-in Functions


Example

Create an iterator object, and print the items:

x = iter(["apple", "banana", "cherry"])
print(next(x))
print(next(x))
print(next(x))
Run example »

Definition and Usage

The iter() function returns an iterator object.


Syntax

iter(object, subclass)

Parameter Values

Parameter Description
object Required. An iterable object
sentinel Optional. If the object is a callable object the iteration will stop when the returned value is the same as the sentinel

Related Pages

The reversed() function returns a reversed iterator object.


❮ Built-in Functions