English

What is the purpose of the yield statement?

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?
Chapter 8: Exception Handling & Generate Functions - EXERCISE [Page 158]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 8 Exception Handling & Generate Functions
EXERCISE | Q 8. | Page 158
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×