Python Language What can be iterable


Example

Iterable can be anything for which items are received one by one, forward only. Built-in Python collections are iterable:

[1, 2, 3]     # list, iterate over items
(1, 2, 3)     # tuple
{1, 2, 3}     # set
{1: 2, 3: 4}  # dict, iterate over keys

Generators return iterables:

def foo():  # foo isn't iterable yet...
    yield 1

res = foo()  # ...but res already is