← Python

String Repetition

The * operator repeats a string a given number of times

What it does: String * int repeats the string that many times. Great for drawing separator lines. Multiplying a string by 0 returns an empty string — perfectly valid. * repeats the string — no spaces are added between repetitions. The string '-' is repeated 3 times with no gaps. String repetition produces no spaces — just the character 10 times. 'Python' repeated twice with no separator. The number can go on either side — 10 * '*' is the same as '*' * 10. String repetition requires an integer multiplier. 2.5 is a float and causes a TypeError.

Common mistakes: Line 2 uses x instead of *. Should be: line = "-" * 10. Line 3 is missing quotes around -. Should be: separator = "-" * 15.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What is "*" * 5?
****** * * * *
Matches
❌ 'Ha' * 2.5
Error: Multiplier must be int
Applying
Meanings
Term
"*" * 10
Meaning
* repeats the string - "*" * 10 gives **********.
Practice
laugh = "Ha" * 5
Testing
Gaps
line = "-" 20
Check Answer
Spots
1stars = "*" * 5
2line = "-" x 10

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'African Wild Dog' badge — Savannah Streak, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What is "*" * 5?
A. ***** ✓
B. * * * * *
* repeats the string — no spaces are added between repetitions
2. What is "-" * 3?
A. - - -
B. --- ✓
The string '-' is repeated 3 times with no gaps
3. What is "Ha" * 3?
A. HaHaHa ✓
B. Ha Ha Ha
The whole string 'Ha' is repeated back-to-back — no spaces added
4. What is "=" * 10?
A. = = = = = = = = = =
B. ========== ✓
String repetition produces no spaces — just the character 10 times
5. Does "*" * 5 add spaces?
A. Yes
B. No ✓
* just repeats the exact string — spaces only appear if the string contains them

Match the Pairs

'Ha' * 2.5 Error: Multiplier must be int
'abc' * 'abc' Error: Can't multiply str by str
line = '-' * 20 Valid: Repeats - 20 times
'Ha' * 0 Ok: Returns empty string
print('Ha' * 3) Output: HaHaHa
print('*' * 5) Output: *****

Key Term

"*" * 10
* repeats the string - "*" * 10 gives **********.~~"-" * 5

Fill in the Blanks

1. line = "-" * 20 # Output: --------------------
2. stars = "*" * 10 # Output: **********
3. border = "=" * 15 # Output: ===============
4. laugh = "Ha" * 3 # Output: HaHaHa
5. separator = 20 * "-" # Output: --------------------

Spot the Error

Question 1
A stars = "*" * 5
B line = "-" x 10
C print(line)
Line B — Line 2 uses x instead of *. Should be: line = "-" * 10
Question 2
A border = "=" * 20
B laugh = "Ha" * 3
C separator = - * 15
D print(separator)
Line C — Line 3 is missing quotes around -. Should be: separator = "-" * 15
Question 3
A stars = "*" * 10
B line = "-" * "5"
C print(line)
Line B — Line 2 puts the number in quotes. Use: line = "-" * 5
Question 4
A pattern = "ABC" * 3
B line = "-" * 20
C dots = "." 5
D print(dots)
Line C — Line 3 is missing *. Should be: dots = "." * 5
Question 5
A border1 = "#" * 10
B border2 = 15 * "#"
C laugh = Ha * 3
D print(laugh)
Line C — Line 3 is missing quotes. Should be: laugh = "Ha" * 3
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?