Skip to content
BENIBIX Learn

Integer

Development🧩 Programming ConceptsData and Variables

Also known as int, Whole Number

A whole number, like 7, 0 or -12, with nothing after the point.

Think of it like

Think of it like counting apples. You can have 3 or 4, but not 3 and a bit.

Example

A shop counts 3 books in a cart as the integer 3. Half a book cannot be bought, so a whole number fits.

Why it matters

Counts, positions and ids are integers. Using the right type keeps the sums exact.

Definition

An integer is a whole number with no part after the point. 7, 0 and -12 are integers, but 2.5 is not. Programs use integers for counting things, like items in a cart or the number of a page. Maths on integers is exact, so no tiny errors creep in. Most languages call the type int.

Example code

python
>>> 7 // 2
3
>>> int("12") + 1
13
Dividing whole numbers drops the half. And int() turns text into a number.

Common mistake

Expecting 7 divided by 2 to be 3 in every language. Some give 3, some give 3.5, so check which one you have.

Key takeaways

  1. 1
    No fractions. Only whole numbers, below or above zero.
  2. 2
    Exact maths. Adding integers never gives a rounding error.
  3. 3
    For counting. Use them for items, pages and ids.

Compare

Learn it properly