Examveda

How can you create an infinite generator in Python?

A. By using a for loop

B. By using the iter() function

C. By using the while loop

D. By using the infinity() function

Answer: Option C

Solution (By Examveda Team)

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.

This Question Belongs to Python Program >> Generators And Iterators

Join The Discussion

Related Questions on Generators and Iterators