How to Multiply in Python
What you’ll build or solve
You’ll multiply numbers, repeat sequences, and handle common “why did this TypeError happen?” moments.
When this approach works best
Multiplication in Python works best when you:
Learn Python on Mimo
- Compute totals, prices, areas, or rates (tax, discounts, unit conversions).
- Scale values in a list (convert meters to centimeters, resize inputs, normalize scores).
- Repeat strings or lists for simple patterns (padding, test data, UI separators).
Avoid using plain floats for money when cents must be exact.
Prerequisites
- Python installed
- You know what variables and basic types (
int,float,str,list) are
Step-by-step instructions
1) Multiply numbers with
Use * for basic numeric multiplication.
a=6
b=7
print(a*b)# 42
price=19.99
tax_rate=1.21
print(price*tax_rate)# 24.1879
Option A: control order with parentheses
subtotal=80
discount=0.15
total_a=subtotal*1-discount# wrong intention
total_b=subtotal* (1-discount)# correct
print(total_a)
print(total_b)
What to look for: * follows normal math precedence. Parentheses help you express your intent clearly.
2) Update a value in place with =
Use *= when you want to multiply and store the result back into the same variable.
score=10
score*=2
print(score)# 20
Option A: use = in a loop to build a product
values= [2,3,4]
product=1
forvinvalues:
product*=v
print(product)# 24
What to look for: The accumulator should usually start at 1, not 0, since 0 * anything becomes 0.
3) Multiply sequences the Python way
Python also uses * to repeat sequences. This is not numeric multiplication, but it’s common in real code.
Option A: repeat a string
dash_line="-"*10
print(dash_line)# ----------
Option B: repeat a list
row= [0]*5
grid= [row]*3
print(grid)
What to look for: Repeating a list of lists can create shared references. grid[0] and grid[1] can point to the same inner list.
A safer grid creation:
grid= [[0]*5for_inrange(3)]
grid[0][0]=9
print(grid)
Examples you can copy
Example 1: Calculate the area of a rectangle
width=4.5
height=2
area=width*height
print(area)
Example 2: Convert units by scaling
meters= [1.2,0.5,3.0]
centimeters= [m*100forminmeters]
print(centimeters)
Example 3: Multiply all numbers in a list
values= [1.5,2,4]
product=1
forvinvalues:
product*=v
print(product)
Example 4: Repeat a pattern for a simple output format
title="Report"
print(title)
print("="*len(title))
Example 5: Multiply with exact decimal math (useful for money)
fromdecimalimportDecimal
price=Decimal("19.99")
tax_rate=Decimal("1.21")
total=price*tax_rate
print(total)
Example 6: Build a multiplication table
table= [[row*colforcolinrange(1,6)]forrowinrange(1,6)]
forrowintable:
print(row)
Common mistakes and how to fix them
Mistake 1: Using ^ for multiplication or powers
What you might do
print(2^3)
Why it breaks
^ is bitwise XOR in Python, not exponentiation.
Fix
Use * for multiplication and ** for powers.
print(2*3)# 6
print(2**3)# 8
Mistake 2: Getting shared rows from [row] * n
What you might do
row= [0]*3
grid= [row]*2
grid[0][0]=9
print(grid)
Why it breaks
Both rows reference the same list, so one change appears in every row.
Fix
Create each row separately.
grid= [[0]*3for_inrange(2)]
grid[0][0]=9
print(grid)
Mistake 3: Expecting = to multiply each list item
What you might do
nums= [1,2,3]
nums*=2
print(nums)# [1, 2, 3, 1, 2, 3]
Why it breaks
For lists, *= repeats the list. It does not multiply each element.
Fix
Multiply each element with a loop or a list comprehension.
nums= [1,2,3]
nums= [n*2forninnums]
print(nums)# [2, 4, 6]
Troubleshooting
If you see:
TypeError: can't multiply sequence by non-int of type 'float'
You tried something like "hi" * 2.5 or [1, 2] * 3.0. Convert the multiplier to int if repetition is the goal.
TypeError: unsupported operand type(s) for *
Check the types with type(a) and type(b). Convert strings to numbers with int(...) or float(...) when needed.
If a grid “changes everywhere,” you probably used [row] * n. Switch to a list comprehension to build rows independently.
Quick recap
- Use
a * bto multiply numbers. - Use
=to multiply and store back into the same variable. - Use
"text" * nor[item] * nto repeat sequences with an integer. - Build 2D lists with a list comprehension to avoid shared rows.
- Use a list comprehension to multiply every element in a list.
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot