Aug 30, 2020 in Python
Q: Can you please help to clarify what are Python Language Generators?

1 Answer

0 votes
Aug 30, 2020
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.
Click here to read more about Python
Click here to read more about Insurance
...