Python’s Itertool is a module that provides various functions that work on iterators to produce complex iterators. This module works as a fast, memory-efficient tool that is used either by themselves or in combination to form iterator algebra.
Note: For more information, refer to Python Itertools
itertools.repeat()falls under the category of infinite iterators. In
repeat() we give the data and give the number, how many times the data will be repeated. If we will not specify the number, it will repeat infinite times. In repeat(), the memory space is not created for every variable. Rather it creates only one variable and repeats the same variable.
Syntax: repeat(val, num)
val: The value to be printed.
num: If the optional keyword num is mentioned, then it repeatedly prints the passed value num number of times, otherwise prints the passed value infinite number of times.
Printing the numbers repeatedly : [25, 25, 25, 25]
['GEEKSFORGEEKS', 'GEEKSFORGEEKS', 'GEEKSFORGEEKS']
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course