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

Python Arithmetic Operators

Arithmetic operators are the math buttons on a calculator, such as plus, minus, times and divide. Python uses them to do sums with numbers.
Syntax
python
result = a + b  # also -, *, /, //, %, **

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)  # numeric addition
print(5 - 3)  # numeric subtraction
print("Hello" + " " + "World")  # + concatenates strings instead of adding

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)
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Expecting / to return an integer: 7 / 2 gives 3.5, and even 6 / 3 gives 2.0; use // for whole-number division.
  2. Thinking -7 // 2 is -3; floor division rounds toward negative infinity, giving -4.
  3. Using ^ for exponentiation, as in 2 ^ 3, which is bitwise XOR (1); use 2 ** 3.

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.