Iteration is a generic term that describes the procedure for taking elements of something in turn. In a more general sense, it is a sequence of instructions that is repeated a certain number of times or before the specified condition is fulfilled.
An iterable is an object that can return elements one at a time. It is also an object from which an iterator can be derived.
Examples of iterables:
all sequences: list, string, tuple
In Python, the
iter function is responsible for getting an iterator:
In : lista = [1, 2, 3] In : iter(lista) Out: <list_iterator at 0xb4ede28c>
iter function will work on any object that has
__iter__ method returns an iterator.
If this method is not available,
iter function checks if there
__getitem__ method that allows getting elements by index.
__getitem__ is present an iterator is returned, which
iterates through the elements using index (starting with 0).
In practice, the use of
__getitem__ means that all sequence elements
are iterable objects. For example, a list, a tuple, a string. Although
these data types have