Built-in Functions and Types

iter()

Obtain an iterator from an iterable or create a sentinel-controlled iterator. The one-argument form uses the iteration protocol, falling back to successive integer indexing for objects implementing the sequence protocol. The two-argument form repeatedly calls a zero-argument callable until a result compares equal to the sentinel, which is not yielded. Unsupported inputs raise TypeError.

Formal Syntax & Structure

python syntaxpython
iter(object, /)iter(callable, sentinel, /)

Parameters & Attributes

NameTypeDescription
objectiterable or sequence-protocol objectRequired in the one-argument form.
callablezero-argument callableRequired in the two-argument form.
sentinelobjectTermination value; required with callable.

Return Value

iterator

An object with __next__(); iter(existing_iterator) normally returns that iterator itself.

Working Example

Example Snippetpython
readings = iter([4, 8, 0, 9])print(list(iter(lambda: next(readings), 0)))print(next(readings))
Python Reference