-
-
Save IndhumathyChelliah/5524f0dcbbb97637bd5c91849d8d2951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
#times argument is not mentioned. It will result in infinite loop. | |
l1=itertools.repeat(2) | |
print (next(l1))#Output:2 | |
print (next(l1))#Output:2 | |
#string is used as an argument.times argument is mentioned as 10.It will repeat the string 10 times. | |
l2=itertools.repeat("hello",times=10) | |
for i in l2: | |
print (i,end=" ")#Output:hello hello hello hello hello hello hello hello hello hello | |
print (" ") | |
#list is used as argument | |
l3=itertools.repeat([1,2,3],times=3) | |
for i in l3: | |
print (i,end=" ")#Output:[1, 2, 3] [1, 2, 3] [1, 2, 3] | |
print (" ") | |
#tuple is used as an argument | |
l4=itertools.repeat(('red','blue'),times=3) | |
for i in l4: | |
print (i,end=" ")#Output:('red', 'blue') ('red', 'blue') ('red', 'blue') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment