capypad
0 day streak
python / beginner
Snippet

String Repetition

In Python, you can use the multiplication operator (*) with a string and an integer to repeat the string multiple times.

snippet.py
python
1
2
3
4
5
separator = "-" * 10
title = "PYTHON"
print(separator)
print(title)
print(separator)
Breakdown
1
separator = "-" * 10
Creates a string consisting of 10 hyphens.
2
title = "PYTHON"
Defines a simple string variable.
3
print(separator)
Prints the line of hyphens to create a visual border.