In terms of function execution, what is the difference between yield and return?

  • 'return' immediately terminates the function, returning a value to the caller.
  • 'return' suspends the function's state, allowing it to resume execution later.
  • 'yield' immediately terminates the function, returning a value to the caller.
  • 'yield' suspends the function's state, allowing it to resume execution later.
'yield' and 'return' serve different purposes in Python. 'yield' is used in generators to pause execution and later resume it, whereas 'return' terminates the function.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *