Python – Repeat a String N Times

Repeat a String N Times

Given a string myStr and a count n, we have to concatenate the string myStr to itself such that the given string appears in the resulting string for n times.

To repeat given string N times in Python, we can use Multiple Concatenation operator * . The operator takes the string and the number as operands, and returns a string self-concatenated by given number of times.


In the following program, we take a string myStr and count in n variables, and repeat the string myStr for n times.

Python Program

myString = 'cherry'
n = 4

output = myString * 4

print(f'Input  : {myString}')
print(f'Output : {output}')


Input  : cherry
Output : cherrycherrycherrycherry


In this tutorial of Python Examples, we learned how to repeat a given string for specific number of times, with the help of well detailed examples.