Python Numbers and Data Types for Beginners
Integers, floats, booleans, and arithmetic in Python — what a data type is, when to use each, and how type() tells them apart.

Before a computer can do anything useful with a value, it has to know what kind of value it is. 5 and "5" look almost identical on screen, but one you can multiply and the other you can't — and Python decides which is which based on the value's data type. Get types straight now and a whole category of confusing errors stops happening to you later.
What is a data type?
A data type is the category a value belongs to, and that category decides what you're allowed to do with it. Whole numbers go in one box, decimals in another, true/false answers in a third. The box isn't just labeling — it controls behavior. You can divide a number by 2; you can't divide the word "cat" by 2, and Python will stop you with an error if you try.
In the last lesson you stored values in variables. Every one of those values had a type, whether you thought about it or not. Now we'll look at the three number-ish types you'll use constantly: int, float, and bool.
int
An int is a whole number — no decimal point. 5, -12, 0, 1000000. You write them exactly as you'd expect, no quotes:
age = 30
score = -7The reason ints matter early is arithmetic. Python has the operators you know from school plus a few that are worth a closer look:
| Operator | Name | 7 ? 2 gives |
|---|---|---|
+ | add | 9 |
- | subtract | 5 |
* | multiply | 14 |
/ | divide | 3.5 |
// | floor divide | 3 |
% | modulo | 1 |
** | power | 49 |
The first three are obvious. The other three trip people up, so here's what each one actually does.
// is floor division. It divides and then throws away everything after the decimal point, rounding down to a whole number. 7 // 2 is 3, not 3.5. Reach for it when a fraction makes no sense — how many full boxes of 12 do you need for 50 items, that kind of thing.
% is modulo, the remainder left over after division. 7 % 2 is 1 because 2 goes into 7 three times with 1 left over. It's the classic "is this number even?" check: if n % 2 is 0, n is even.
** is power, not multiplication. 2 ** 3 means 2 to the power of 3, which is 2 * 2 * 2, which is 8. People reach for ^ here out of habit from math class; in Python ^ does something else entirely, so use **.
Run these and change the numbers to build a feel for them:
Quick check
What is 7 // 2 in Python?
float
A float is a number with a decimal point: 3.14, 0.5, -2.0, 99.99. Anything that needs a fraction — a price, a temperature, an average — is a float.
Here's the part that surprises new programmers. The plain division operator / always hands back a float, even when the math comes out even:
print(4 / 2) # 2.0, not 24 / 2 is 2.0, with the .0 stuck on. Python's rule is simple: / is for fractional division, so its answer is always a float, no exceptions. If you wanted the whole number 2, that's a job for //.
Floats also spread. Mix a float into a calculation and the result comes out as a float — 3 + 1.5 is 4.5, an int plus a float gives a float. That's usually what you want; just don't be surprised when a .0 shows up.
Tip
/ always gives you a float — 4 / 2 is 2.0, not 2. When you want a clean whole-number result, use // instead. This catches almost everyone once.
bool
A bool (boolean) has exactly two possible values: True and False. Capital first letter, no quotes — True is a value, "True" is text.
is_logged_in = True
has_paid = FalseYou'll rarely type True and False by hand. Mostly they show up as the result of a comparison — when you ask Python a yes/no question, a bool is the answer:
print(5 > 3) # True
print(10 == 2) # False5 > 3 is a question ("is 5 greater than 3?") and True is the answer. These comparison and logic operators get their own lesson later, so don't worry about memorizing them. For now, just know that the True/False you'll see everywhere are bools, and they're their own data type.
Checking a type with type()
When you're not sure what type a value is — and you will hit this constantly while debugging — type() tells you. Hand it any value and it reports the category:
That last line is the lesson from earlier, proven. 4 / 2 looks like it should be an int, but type() confirms it's a float, because / always produces one.
type() is your fastest debugging tool. A surprising number of bugs are really "I thought this was an int but it's actually text," and one type() call shows you in a second.
Recap and what's next
Every value in Python has a type, and the type decides what you can do with it. int is whole numbers and gives you the arithmetic operators — including // for floor division, % for the remainder, and ** for powers. float is decimals, and / always produces one even when the division is even. bool is just True and False, usually born from a comparison. And type() tells you which is which whenever you're unsure.
Numbers are one half of the data you'll work with. The other half is text — and Python has a lot of sharp tools for it. Next up: working with text: Python strings.

Written by
Rhythm Bhiwani
Engineer and relentless builder, happiest reverse-engineering hard problems until they click.
Enjoyed this?
Tap the heart to leave some love.
Be the first to react
Comments
Join the conversation.
Loading comments…


