ProgrammingEasyInfosys · Accenture · Capgemini pattern

Which keyword turns an ordinary Python function into a generator function?

  1. A. yield
  2. B. lambda
  3. C. async
  4. D. return

Correct answer: A. yield

Any function whose body contains yield is a generator function: calling it returns a generator object that produces values lazily, one per next().

More Python Programming questions

Exams that ask this topic