Generators

Generator functions allow you to declare a function that behaves like an iterator.

# Generator
def my_range(start, stop):
    counter = start
    while counter < stop:
        yield counter
        counter += 1

# Invoking the generator within a for-loop
for n in my_range(0, 10):
   print(n)

References