ExamVeda
Login
Home
Generators and Iterators
?

How can you create an infinite generator in Python?

Answer & Solution
Correct Answer: Option C
The correct answer is Option C: By using the while loop.
You can create an infinite generator in Python by using a while loop. Inside the while loop, you can use the yield statement to yield values infinitely. Since a while loop can continue indefinitely as long as its condition remains true, you can use it to create a generator that produces an infinite sequence of values. This allows you to generate values lazily, one at a time, without having to predefine the length of the sequence.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.