Python iter() function
Published February 16, 2022The iter() function in Python is used to return the iterator of the specified object. This method generates an object that can be iterated over one element at a time. These items are essential in loops and while loops.
The Syntax
The iter() has the following simple syntax()
iter(object, sentinel) |
Where:
Object: This is the object that will be iterated over.
Sentinel: these are the values that will represent the end of the sequence.
Example
x = [5, 4, 3, 2, 1] |
Output
The type of the list is : <class 'list'> |
Article Contributed By :
|
|
|
|
429 Views |