Back to course

The Integer Data Type (int) and Basic Arithmetic

Python Programming: The 0 to Hero Bootcamp

Integers (int)

Integers are whole numbers, positive or negative, without a decimal point (e.g., 10, -500, 0).

python population = 1000000 year = 2024 neg_num = -50

Basic Arithmetic Operators

OperatorOperationExample
+Addition5 + 3 -> 8
-Subtraction10 - 4 -> 6
*Multiplication6 * 7 -> 42
/Division10 / 3 -> 3.333... (Always returns a float)
//Floor Division10 // 3 -> 3 (Discards the remainder)
%Modulo (Remainder)10 % 3 -> 1
**Exponentiation2 ** 3 -> 8 (2 cubed)

Operator Precedence

Python follows standard mathematical order of operations (PEMDAS/BODMAS):

  1. Parentheses ()
  2. Exponents **
  3. Multiplication *, Division /, Floor Division //, Modulo % (from left to right)
  4. Addition +, Subtraction - (from left to right)

python result = 5 + 2 * (10 / 5) ** 2

5 + 2 * (2.0) ** 2

5 + 2 * 4.0

5 + 8.0

13.0

print(result)