iter Function in Python Syntax

The iter() method in Python has the following syntax:

Syntax : iter(obj, sentinel)

Parameters : 

  • obj : Object which has to be converted to iterable ( usually an iterator ).
  • sentinel : value used to represent end of sequence.

Returns : Iterator object

Properties of Iterators

  • The iteration object remembers the iteration count via the internal count variable.
  • Once the iteration is complete, it raises a StopIteration exception and the iteration count cannot be reassigned to 0.
  • Therefore, it can be used to traverse the container just once.

Python iter() method

python iter() method returns the iterator object, it is used to convert an iterable to the iterator.

Similar Reads

iter Function in Python Syntax

The iter() method in Python has the following syntax:...

Python iter() Function Examples

Let us see a few examples of the iter function in Python....