What does the Yield Keyword do?
yield keyword is used to create a generator function. A type of function that is memory efficient and can be used like an iterator object.
In layman terms, the yield keyword will turn any expression that is given with it into a generator object and return it to the caller. Therefore, you must iterate over the generator object if you wish to obtain the values stored there. we will see the yield python example.
Python | yield Keyword
In this article, we will cover the yield keyword in Python. Before starting, let’s understand the yield keyword definition.
Syntax of the Yield Keyword in Python
def gen_func(x): for i in range(x): yield i
Contact Us