How is a generator function different from a normal function in Python?

  • A generator function is a built-in Python function
  • A generator function is defined using the generator keyword
  • A generator function returns multiple values simultaneously
  • A generator function yields values lazily one at a time
A generator function differs from a normal function in that it uses the yield keyword to yield values lazily one at a time, allowing it to generate values on-the-fly without consuming excessive memory.
Add your answer
Loading...

Leave a comment

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