ExamVeda
Login
Home
Generators and Iterators
?

How is a generator object iterated in a for loop?

Answer & Solution
Correct Answer: Option C
The correct answer is Option C: By using the for keyword.
A generator object is iterated in a for loop by using the for keyword. When you use a for loop to iterate over a generator object, Python automatically calls the next() function on the generator object to retrieve each value yielded by the generator function. This process continues until the generator function is exhausted, at which point the loop terminates. This convenient syntax allows you to easily iterate over the values produced by a generator without explicitly calling next() or managing the loop termination condition.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.