PRACTICE / UNDERSTAND / REPEAT

Python: Generators

Practice generators with self-contained questions. Check your answer, then use the explanation to understand the reasoning.

16 questionsAnswers explainedFree · no login
Question 1 of 16
Generators · MCQQuestion link ↗

What does `yield` do inside a function?

Choose one answer
Answer & explanation

Answer: Produces a value and suspends the generator

`yield` produces a value while preserving generator state for the next iteration.