all Python 3Strings (str)term
* string repetition
operators
The * operator repeats a string n times. For n <= 0 it returns an empty string.
Syntax
s * n | n * s
The multiplier has to be an int: 'ab' * 2.0 raises TypeError, so convert a float first. Unlike lists, where [[0]] * 3 gives three references to the same inner list, strings carry no such trap — being immutable, there is nothing to mutate through a shared reference.
Examples
print('ab' * 3)
# → 'ababab'
print('-' * 20)
# → '--------------------'
print(repr('ha' * 0))
# → ''
sep = '=-' * 5
print(sep)
# → '=-=-=-=-=-'
print(3 * 'go!')
# → 'go!go!go!'
See also
Open in the full glossarydocs.python.orgReport an inaccuracy