Skip to main content

Python Arithmetic Operators

Satellite · Operators

Python Arithmetic Operators

Arithmetic is the foundation of expression building. Learn how each operator behaves, including floor division and exponent nuances.

Operator overview

OperatorMeaningExample
+Additiontotal = a + b
-Subtractionbalance = income - expenses
*Multiplicationarea = width * height
/True division3 / 2 == 1.5
//Floor division3 // 2 == 1
%Modulo (remainder)5 % 2 == 1
**Exponentiation2 ** 3 == 8

Examples

hours = total_minutes // 60
minutes = total_minutes % 60

compound_interest = principal * (1 + rate) ** years

Pitfalls

  • / always returns float, even when dividing integers.
  • % follows the divisor's sign: -5 % 2 == 1.
  • Use math.isclose to compare floats due to precision issues.

Next up in your learning path