A generator is a function that has one or more yield statements.
Example:
>>>def gen_demo(a):
yield a
a = a+10
yield a
a = a+30
yield a
>>>gen_a = gen_demo(10)
>>>gen_a.next()
10
>>>gen_a.next()
20
>>>gen_a.next()
50
if we run gen_a.next(), it gives StopIteration error because the generator is done with yielding values by this time. Unlike a function's return statement a generator function can remember the point where it has left off, so that when next method is called again it continues yielding values from there after. We will see how to generate datasets with a huge number of elements in our next lesson.