Iteration is a process in which one single element is taken at a time given n elements.
Iterable is an object that one iterates over elements,
while iterator is an object that generates values during iteration and is also returned by the iterable object.
Iterable object implements __iter__() method and returns an iterator object.
Python Built-in iterable objects are list, sets, strings,
If __iter__() method does not work then __getitem__() is used.
Iterators implement the __next__() method. This means that the next values are returned until all the values are exhausted. Also the iterator object gets updated.
Let us take an example:
Obj1 = 'Pie' # Obj1 is an string and also is Iterable
Piece = iter(Obj1) #Piece is Iterator
next(Piece)
'P'
next(Piece)
'i'
next(Piece)
'e'
next(Piece)
---------------------------------------------------------------------------
StopIteration Traceback (most recent call last)
<ipython-input-26-aad7e70238c3> in <module>
----> 1 next(Piece)
StopIteration: