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
1
2
3
4
5
separator = "-" * 10title = "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.