Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 91)
91.
How does the itertools.cycle() function behave when used with an empty generator?
It raises a ValueError
It returns an empty iterable
It raises a StopIteration exception
It enters an infinite loop without producing any elements
Answer: Option
Explanation:
itertools.cycle() raises a StopIteration exception when used with an empty generator, as there are no elements to repeat.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.