Python Does the Math
The problem...
You have numbers. But numbers alone don't do much.
You need to work with them. Add. Subtract. Multiply. Divide.
And you need Python to do it for you.
The idea!
Python supports all basic arithmetic operations out of the box.
No imports. No setup. Just write the operation and Python calculates it.
The operators
+— addition-— subtraction*— multiplication/— division//— floor division (whole number result)%— modulo (remainder)**— exponentiation (power)
In practice
print(10 + 3) # 13
print(10 - 3) # 7
print(10 * 3) # 30
print(10 / 3) # 3.3333333333333335
print(10 // 3) # 3
print(10 % 3) # 1
print(10 ** 3) # 1000
Why this matters?
You can use variables instead of raw numbers — and that's where it gets useful.
price = 49.99
quantity = 3
discount = 10
total = price * quantity
after_discount = total - discount
print(f"Total: {total}") # Total: 149.97
print(f"After discount: {after_discount}") # After discount: 139.97
Going further
Python follows the standard order of operations — multiplication and division before addition and subtraction.
print(2 + 3 * 4) # 14 — not 20
print((2 + 3) * 4) # 20 — parentheses first
When in doubt, use parentheses. They make your intent clear.
Updating a variable
Often you need to update a variable based on its current value.
price = 12
price = price + 3
print(price) # 15
This works. But Python has a shorter way.
price = 12
price += 3
print(price) # 15
price += 3 means: take the current value of price and add 3 to it. Same result, less typing.
Works with all operators:
x = 10
x += 3 # x = 13
x -= 3 # x = 10
x *= 2 # x = 20
x /= 4 # x = 5.0
x //= 2 # x = 2.0
x **= 3 # x = 8.0
What's really happening
Python evaluates the expression and returns a value.
That value has a type — and the type depends on the operation.
print(type(10 + 3)) # <class 'int'>
print(type(10 / 3)) # <class 'float'> — division always returns float
print(type(10 // 3)) # <class 'int'>
Heads up!
- Division
/always returns a float — even if the result is whole:10 / 2 = 5.0 - Floor division
//rounds down — always:7 // 2 = 3, not 4 - Modulo
%gives the remainder — useful for checking if a number is even or odd - Python follows order of operations — use parentheses when in doubt
+=is shorthand forx = x + something— works with all operators
The mindset shift
Stop thinking: "I need a calculator."
Start thinking: "Python is my calculator — and it never makes mistakes."
What you should understand now
- Python supports all basic arithmetic operators
- Division always returns a float
- Floor division returns an int
- Order of operations applies — use parentheses to be explicit