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
| Name | Type | Description |
|---|---|---|
| object | iterable or sequence-protocol object | Required in the one-argument form. |
| callable | zero-argument callable | Required in the two-argument form. |
| sentinel | object | Termination 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))