?
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.
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.
Join the Discussion
Login to post a comment or share your explanation.
Login