Python Arithmetic Operators
In this page:
Addition and Subtraction
Addition (+) and subtraction (-) work exactly as expected on numbers, and Python extends + to also mean concatenation when both operands are strings or lists, joining them end to end instead of adding numerically.
Example: Addition and Subtraction
print(5 + 3)
print(5 - 3)
print("Hello" + " " + "World")
Multiplication and Division
Multiplication (*) multiplies two values, while true division (/) always returns a float in Python 3 even when dividing two whole numbers evenly — 10 / 2 gives 5.0, not 5, a common surprise for people coming from other languages.
Example: Multiplication and Division
print(4 * 3)
print(10 / 2)
Floor Division
Floor division (//) divides and then rounds the result down to the nearest whole number, discarding any remainder — useful whenever you need a whole-number result, like splitting items evenly into groups.
Example: Floor Division
print(10 // 3)
Modulo Operator
The modulo operator (%) returns what's left over after division rather than the quotient itself, which is why number % 2 == 0 is the standard idiom for checking whether a number is even.
Example: Modulo Operator
number = 7
print(number % 2 == 0)
Exponentiation
The exponentiation operator (**) raises the left operand to the power of the right one — 2 ** 10 evaluates to 1024 — and is Python's built-in replacement for calling a separate power function.
Example: Exponentiation
print(2 ** 10)
Chapter Quiz — Complete all 16 topics to unlock
0/16 topics done
Complete these topics first:
- Python print()
- Python input()
- Python Format Strings
- Python f-strings
- Python String Formatting
- Python Arithmetic Operators
- Python Relational Operators
- Python Logical Operators
- Python Bitwise Operators
- Python Assignment Operators
- Python Increment & Decrement
- Python Ternary Operator
- Python Operator Precedence
- Python Identity Operators
- Python Membership Operators
- Python Operators