Learning how to do math in Python 3 with operators is one of the most fundamental and frequently used skills in Python programming — numbers appear everywhere (scores, coordinates, money, percentages, physics, data analysis, AI calculations), and Python’s built-in arithmetic operators make calculations clean, readable, and powerful.
In this up-to-date 2025–2026 guide, you’ll master exactly how to do math in Python 3 with operators: addition/subtraction, multiplication/division (including floor division //), modulo %, exponentiation **, unary operations, operator precedence (PEMDAS), compound assignment (+=, *= etc.), floating-point precision tips, and best practices. All examples are tested on Python 3.10–3.13.
Key Takeaways – How to Do Math in Python 3 with Operators
- Do math in Python 3 with operators using familiar symbols: +, -, *, /, //, %, **.
- / always returns float (even with integers) — major difference from Python 2.
- // = floor division (integer result, rounds down).
- % = modulo (remainder after division) — great for multiples, cycles, even/odd checks.
- ** = exponentiation (power) — 2 ** 10 = 1024.
- Operator precedence follows PEMDAS (Parentheses, Exponents, Multiplication/Division, Addition/Subtraction).
- Compound assignment: x += 5 is shorthand for x = x + 5 — very common in loops.
- Floats have precision issues (0.1 + 0.2 != 0.3) — use decimal module for money/finance.
- Unary +/- for sign change or identity.
Prerequisites
- Python 3.8+ installed
- Basic Python knowledge (print, variables)
- Interactive shell (python3) or script file
1. Addition & Subtraction (+ and -)
Basic and compound:
a = 88
b = 103
print(a + b) # 191
c = -36
print(c + 25) # -11
x = 75.67
print(x - 32) # 43.67
Compound assignment:
score = 95
score += 5 # score = score + 5
print(score) # 100
2. Multiplication & Division (* and /)
print(100.1 * 10.1) # 1011.01 (float result)
print(80 / 5) # 16.0 (always float in Python 3)
print(11 / 2) # 5.5 (true division)
Floor division // (rounds down to integer):
print(10 // 3) # 3
print(-10 // 3) # -4 (rounds down, not toward zero)
3. Modulo (%) – Remainder
print(85 % 15) # 10
print(36.0 % 6.0) # 0.0
print(17 % 2) # 1 (odd number check)
Common uses:
- Even/odd: n % 2 == 0
- Cycles: index % len(list)
- Multiples: total % 100 == 0
4. Exponentiation (**)
print(2 ** 10) # 1024
print(52.25 ** 7) # huge float: 1063173305051.292
5. Unary Operations (+ and -)
x = 3.3
print(+x) # 3.3 (identity)
print(-x) # -3.3 (negation)
y = -19
print(-y) # 19 (changes sign)
6. Operator Precedence (PEMDAS)
Python follows standard math order:
print(10 + 10 * 5) # 60 (multiplication first)
print((10 + 10) * 5) # 100 (parentheses first)
# Full PEMDAS
print(2 ** 3 * 4 / 2 + 5) # 37.0
# 8 * 4 / 2 + 5 → 32 / 2 + 5 → 16 + 5 → 21
7. Compound Assignment Operators
Shorthand for common updates:
x = 10
x += 5 # x = x + 5 → 15
x -= 3 # x = x - 3 → 12
x *= 2 # x = x * 2 → 24
x /= 4 # x = x / 4 → 6.0
x //= 2 # x = x // 2 → 3
x **= 2 # x = x ** 2 → 9
x %= 5 # x = x % 5 → 4
Very common in loops:
total = 0
for i in range(10):
total += i
print(total) # 45
8. Floating-Point Precision Tip
print(0.1 + 0.2) # 0.30000000000000004 (not 0.3)
Solution for money/finance:
from decimal import Decimal
print(Decimal('0.1') + Decimal('0.2')) # 0.3 (exact)
How to Do Math in Python 3 with Operators – FAQ (2025–2026)
- How do I do math in Python 3 with operators?
Use +, -, *, /, //, %, ** — core how to do math in Python 3 with operators. - What’s the difference between / and // in Python 3?
/ = true division (float result), // = floor division (integer, rounds down). - How do I raise a number to a power in Python 3?
Use **: 2 ** 10 = 1024. - What does % do when doing math in Python 3 with operators?
Returns remainder (modulo) — great for cycles, even/odd, multiples. - What is operator precedence in Python 3?
PEMDAS: Parentheses → Exponents → Multiplication/Division → Addition/Subtraction.
Summary
You now know exactly how to do math in Python 3 with operators: addition/subtraction, multiplication/division/floor, modulo, exponentiation, unary ops, precedence, compound assignment, and precision handling.
Mastering how to do math in Python 3 with operators unlocks scores, coordinates, money calculations, physics simulations, data analysis, game logic, and much more — a daily skill for every Python developer.
Recommended Next Tutorials
- Python Math Module (sqrt, sin, log, etc.)
- Python Decimal for Precise Math
- Python Random Numbers & Statistics
- Build a Simple Calculator Project
- Python Operator Precedence Deep Dive