Home / Python / Reference / Built-in functions

Python iter() function

Get an iterator: an object that gives items one at a time.

Syntax

iter(iterable)

A for loop calls iter for you. Use it yourself together with next to take items one by one.

Parameters

iterableanything you can loop over

Return value

an iterator

Example

Code

it = iter(["a", "b", "c"])
print(next(it))
print(next(it))
print(list(it))     # what is left

Output

a
b
['c']

Related

Learn it step by step in the free lesson Pythonic Python, with exercises that check your answers.