Python yield Keyword
Example
Return three values from a function:
def myFunc():
yield "Hello"
yield 51
yield
"Good Bye"
x = myFunc()
for z in x:
print(z)
Try it Yourself »
Definition and Usage
The yield keyword is used to return a list
of values from a function.
Unlike the return keyword which stops
further execution of the function, the yield
keyword continues to the end of the function.
When you call a function with yield
keyword(s), the return value will be a list of values, one for each
yield.
Related Pages
Use the return
keyword to return only one value, and stop further execution.
Read more about functions in our Python Functions Tutorial.