Repeat String in Python

Sometimes we need to repeat the string in the program, and we can do this easily by using the repetition operator in Python.

Repetition operator is denoted by a '*' symbol and is useful for repeating strings to a certain length.

str = 'Python program'

The above lines of code will display the following outputs:

Python programPython programPython program

Similarly, it is also possible to repeat any part of the string by slicing:

str = 'Python program'
print(str[7:9]*3) #Repeats the seventh and eighth character three times

Subscribe Updates via Email

Join 49,000+ W3schools lovers and get all the latest tutorials, programs, algorithms in your inbox.