A Generator is a kind of function which lets us specify a function that acts like an iterator and hence can get used in a “for” loop.
In a generator function, the yield keyword substitutes the return statement.
# Simple Python Language function
def fn():
return "Simple Python Language function."
# Python Language Generator function
def generate():
yield "Python Language Generator function."
print(next(generate()))
The output is:
Python Language Generator function.