Numbers
Numbers let Python count and do math.
Think of counting toys or measuring juice.
Python has whole numbers and numbers with a dot.
Whole numbers are int. Numbers with a fraction are float.
Integers
An int is a whole number.
No decimal point. Like 0, 7, or 100.
Floats
A float has a decimal point.
Like 2.5 cups of milk.
Use floats when parts of a whole matter.
Basic math
Python can add, subtract, multiply, and divide.
+ add
- subtract
* multiply
/ divide (gives a float)
// divide and drop the leftover
% remainder
** power, like 2 ** 3 means 2*2*2
Mixing int and float
If one side is a float, the answer often becomes a float.
Division with / always gives a float, even for 10 / 2.
Converting types
Use int() and float() to change shapes.
int on a float drops the fraction. It does not round up.
Rounding and helpers
round can tidy a float.
abs makes a number positive.
min and max pick the smallest or biggest.
Tip: Use int for counting. Use float when you need pieces of a whole.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.