English

How is yield different from return?

Advertisements
Advertisements

Question

How is yield different from return?

Distinguish Between
Advertisements

Solution

Basis of Difference yield return
Purpose Produces values from a generator Sends back a final value from a function
Execution Pauses the function and can resume later Terminates the function immediately
State Preserves local variables and execution state Function state is discarded after completion
Output Can produce a sequence of values Normally produces one result
Memory use Generally memory-efficient for large sequences May require a complete result to be created first
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 9. | Page 158
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×