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
1
2
3
word = "Python! "repeated = word * 3print(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! '.