ExamVeda
Login
Home
Generators and Iterators
?

How are values produced in a generator function?

Answer & Solution
Correct Answer: Option A
The correct answer is Option A: Using the yield keyword.
Values are produced in a generator function using the yield keyword. When a generator function encounters a yield statement, it temporarily suspends its execution and returns the yielded value. Subsequent calls to the generator function continue execution from where it was previously suspended, allowing it to generate values lazily, one at a time, as needed. This mechanism enables generators to efficiently handle large datasets or infinite sequences without loading all values into memory at once.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.