Repeat objects in Python (using itertools.repeat)

You can repeat objects using the itertools.repeat().

import itertools

r = itertools.repeat('ABC', 4)

print(r)  # repeat('ABC', 4)
print(type(r))  # <class 'itertools.repeat'>

for i in r:
    print(i)

# ABC
# ABC
# ABC
# ABC

The second argument of itertools.repeat() represents repeating count. It is optional but should not be omitted.

import itertools

r = itertools.repeat('ABC')

for i in r:
    print(i)

You must not write the above code because it generates an endless loop.

Python Itertools

Python Tutorial