Advertisements
Advertisements
Question
What is the purpose of the yield statement?
Short Answer
Advertisements
Solution
The yield statement turns a function into a generator. It returns one value at a time, pauses execution, saves the function's state, and resumes from the same point during the next iteration or next() call. This saves memory because all results do not have to be stored at once.
shaalaa.com
Is there an error in this question or solution?
