Learn Python
>>> operators.op_arithmetic

Arithmetic Operators in Python

#concept

Arithmetic operators perform mathematical calculations on numbers. Python has the familiar +, -, * and / for addition, subtraction, multiplication, and division, plus a few operators most languages don't have as built-ins: // for floor division, % for the remainder (modulo), and ** for exponentiation.

#how it works
1

Two operands, one result

Each operator takes two numbers and produces one value.

2

Standard precedence applies

Multiplication and division run before addition and subtraction, unless parentheses say otherwise — covered fully in Operator Precedence.

3

Mixing int and float promotes to float

Any expression combining the two types produces a float result.

4

True division always returns a float

/ returns a float even when the numbers divide evenly, unlike // which stays an int when both operands are ints.

5

Floor division and modulo are a pair

a // b gives how many times b fits into a; a % b gives what is left over — together they reconstruct a.

#example
print(7 + 3)
print(7 - 3)
print(7 * 3)
print(7 / 3)
print(7 // 3)
print(7 % 3)
print(7 ** 2)
Output
10
4
21
2.3333333333333335
2
1
49
1+, -, and * behave exactly as expected.
2/ (true division) returns 2.333..., a float, even though both 7 and 3 are ints.
3// (floor division) returns 2 — how many whole times 3 fits into 7.
4% (modulo) returns 1 — what is left over after 3 fits into 7 twice (2 × 3 = 6, and 7 - 6 = 1).
5** (exponent) computes 7 squared.
#variants

Addition (+)

Combines two numbers — or concatenates two strings or lists, covered in their own topics.

total = 12 + 8
print(total)
Output
20

Floor Division (//)

Divides and rounds down to the nearest whole number, discarding any remainder.

full_boxes = 23 // 5
print(full_boxes)
Output
4

Modulo (%)

Returns the remainder of a division — a common way to check divisibility or cycle through a fixed range.

is_even = 10 % 2 == 0
print(is_even)
Output
True

Exponentiation (**)

Raises a number to a power.

squared = 5 ** 2
print(squared)
Output
25
#use cases
Calculating totals, averages, and other numeric results in everyday scripts
Using modulo to check even/odd, cycle through indices, or convert units like seconds into minutes and seconds
Using floor division to compute whole quantities, like how many full boxes of 12 fit a given count
Using ** for exponential calculations like compound interest or computing powers of 2 in algorithm analysis

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.