0 votes
in Python by
Can you please help to clarify what are Python Language Generators?

1 Answer

0 votes
by
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.

Related questions

0 votes
asked Aug 29, 2020 in Python by Robindeniel
0 votes
asked Aug 30, 2020 in Python by sharadyadav1986
...