Python Programming - Generators - Discussion
Discussion Forum : Generators - General Questions (Q.No. 97)
97.
How does the
itertools.count()
function behave when used with a specified step value?
Answer: Option
Explanation:
itertools.count()
creates an infinite sequence of integers, and if a step value is specified, it increments each subsequent element by that step value.
import itertools
count_by_twos = itertools.count(start=0, step=2)
result = [next(count_by_twos) for _ in range(5)]
print(result) # Output: [0, 2, 4, 6, 8]
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers