Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 72)
72.
How does the itertools.count() function differ from using range()?
They are equivalent in functionality
itertools.count() generates an infinite sequence, while range() creates a finite sequence
range() generates an infinite sequence, while itertools.count() creates a finite sequence
itertools.count() raises a StopIteration exception when exhausted, while range() does not
Answer: Option
Explanation:
itertools.count() generates an infinite sequence of numbers, while range() creates a finite sequence of numbers.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.