capypad
0 day streak
python / beginner
Snippet

Repeating Strings with Multiplication

In Python, you can use the multiplication operator (*) on a string to repeat its content a specific number of times.

snippet.py
python
1
2
3
word = "Python! "
repeated = word * 3
print(repeated)
Breakdown
1
word = "Python! "
Defines a string variable with a trailing space.
2
word * 3
Multiplies the string content by 3, resulting in 'Python! Python! Python! '.