Home >>Python Built-in Functions >Python iter() Function
Python iter() function is used to return an iterator object or to convert the given iterable object to an iterator object.
Syntax:iter(object, sentinel)
Parameter | Description |
---|---|
object | This is a required parameter. It defines an iterable object. |
sentinel | This is an optional parameter. It defines a value and the iteration will stop when the returned value will be equal to this. |
x = iter(["apple", "banana", "mango", "orange"])
print(next(x))
print(next(x))
print(next(x))
print(next(x))
x = iter([1, 2, 3, 4, 5, 6, 7, 8, 9])
print(next(x))
print(next(x))
print(next(x))
print(next(x))
print(next(x))
print(next(x))
print(next(x))
print(next(x))
print(next(x))