← Back to Python Course | Chapter 2: Input, Output & Operators | Lesson 6 of 16

Python Arithmetic Operators

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

python
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

python
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

python
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

python
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

python
print(2 ** 10)

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.