Integer

A whole number with no decimal point, e.g. 42.

An integer (int) is a whole number, positive or negative, with no fractional part. Python integers have unlimited size — they never overflow, so you can compute enormous numbers exactly. Use // for floor (whole-number) division and % for the remainder.

Example
count = 42
print(count + 8)        # ordinary arithmetic
print(7 // 2)           # floor division -> 3
print(2 ** 100)         # exact, no overflow
print(int("100"))       # turn a string of digits into an int
Output
50
3
1267650600228229401496703205376
100

Where this shows up in real Python

Whole numbers count things, index into sequences, drive loop ranges, and store money in whole cents to avoid rounding errors.

Commonly used Integer tools

  • int('42') — turn a string of digits into an int
  • a // b — floor (whole-number) division
  • a % b — the remainder
  • abs(n) — distance from zero
  • 2 ** 10 — exact powers, no overflow
  • divmod(a, b) — quotient and remainder together

Related lessons

Related terms