Pure Python: Multiplying Strings

Whenever you want to create a repeat String in Python, you can use the overloaded * operator.

You can do so like this:

or


(Note the difference in double and single quotes). Under the hood, when Python attempts to multiply two objects, it first tries to call the left object’s __mul__ method. The following piece of code does the same as above, but in a less readable way: