How does yield differ from a simple return keyword in functions. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How does yield differ from a simple return keyword in functions.

Use of yield

26th Sep 2016, 4:01 PM
Siddhant Wade
Siddhant Wade - avatar
2 Answers
+ 6
yield does not destroy the local variables in the function, return does.
12th Oct 2016, 12:51 AM
Jay Azurin
Jay Azurin - avatar
+ 2
A function returns a value after executing it's statements Yield however enables the function to return multiple values for a single function call Thereby enabling us to create lists by calling the function just once.
26th Sep 2016, 4:02 PM
Siddhant Wade
Siddhant Wade - avatar