📚

String Repetition

Repeating Strings with *

The

*
operator can repeat a string a given number of times:

print("Ha" * 3)        # → HaHaHa
print("-" * 20)        # → --------------------
print("🐍 " * 5)      # → 🐍 🐍 🐍 🐍 🐍

This is super handy for creating visual separators, borders, or patterns:

print("=" * 30)
print("    Welcome!")
print("=" * 30)
# → ==============================
# →     Welcome!
# → ==============================

The order doesn't matter —

3 * "Ha"
works the same as
"Ha" * 3
.

💡

💡 Multiplying by 0 gives an empty string:

"hello" * 0
""
. This can be useful in creative ways!

main.pySandbox
main.py