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.
What is a generator in Python?
A. A function that generates random numbers
B. A special type of list
C. A way to define classes
D. A function that yields values one at a time
How is a generator different from a regular function?
A. A generator uses the return keyword
B. A generator can yield multiple values
C. A generator uses the break statement
D. A generator uses the continue statement
What is an advantage of using generators for large datasets?
A. They use more memory
B. They are slower than loops
C. They are easier to implement
D. They use less memory
How do you define a generator function in Python?
A. Using the generator keyword
B. Using the def keyword and yield statement
C. Using the gen keyword
D. Using the function keyword

Join The Discussion