We can use * operator to repeat string n number of times. Below is the syntax for repeating string.
str : Variable containing string and n is the number of times that string will be repeated.
Below are some of the examples.
>> str = ‘Python’
>> string1 = ‘Python language’
‘Python languagePython language’
>> string2 = ‘India is a great country’
‘India is a great countryIndia is a great countryIndia is a great country’
We can also use * operator to repeat some part of a string. First slice the string then use * operator to repeat part of a string.
>> string3 = ‘Python is a programming language’
>>> s = string3[3:4]
>> s = string3[3:9]
‘hon ishon ishon is’
>> s = string3[8:13]
‘s a ps a ps a ps a p’