Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk1 min

How to Repeat a String Multiple Times in Python

Use Python’s * operator to repeat a string, and use join() when you need separators or are assembling many pieces.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Python’s * operator: text * count repeats a string the specified number of times. For example, "ha" * 3 produces "hahaha".

Repeat a string with the * operator

Python treats strings as sequences, so multiplying a string by a count repeats the entire string as a unit. The order of the operands can be reversed:

"ha" * 3       # "hahaha"
3 * "ha"       # "hahaha"
"-" * 8        # "--------"

The Python 3.14.6 tutorial shows the same operation in 3 * 'un' + 'ium', which evaluates to 'unununium' (Python tutorial: An Informal Introduction to Python).

What happens with zero, negative, or non-integer counts?

  • A count of zero produces an empty string: "ha" * 0 is "".
  • A negative count is treated as zero, so "ha" * -2 also produces "".
  • The count must be an integer or an object that implements the __index__() method. A value that does not meet that requirement cannot be used as the repetition count.

These behaviors are specified in the Python 3.14.8 built-in types reference under sequence operations (Python built-in types documentation).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put a separator between repeated copies

Multiplication joins copies directly together. To insert a separator, repeat the string in a sequence and call the separator’s join() method:

", ".join(["ha"] * 3)  # "ha, ha, ha"

When to use join() or StringIO instead

For a fixed number of identical copies, multiplication is the straightforward choice. A different pattern arises when a loop builds one string incrementally from many pieces. Because strings are immutable, repeatedly concatenating pieces can have quadratic runtime cost as the result grows. The Python built-in types reference recommends collecting pieces and using str.join(), or writing incrementally with io.StringIO, to avoid that construction pattern.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

String repetition is not a regular expression

To create repeated text, use an expression such as "a" * 3, which returns "aaa". A regular-expression quantifier such as a{3} describes a pattern that matches three a characters; it is not needed to build a string.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.