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

The 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

Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram