🧩Integer
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
Example code
python
>>> 7 // 2
3
>>> int("12") + 1
13Common mistake
Key takeaways
- 1No fractions. Only whole numbers, below or above zero.
- 2Exact maths. Adding integers never gives a rounding error.
- 3For counting. Use them for items, pages and ids.