🔢 Numbers & Math, lesson 1 of 5
Integers and floats
Python's two kinds of numbers and the basic arithmetic operators.
8 min
2 exercises
2 quizzes
0/4 solved
Getting Python ready… examples can run in a moment.
Python has two main kinds of numbers:
- int (integer): whole numbers like
7,0or-42 - float (floating point): numbers with a decimal
point like
3.14or2.0
You can do math with the usual operators: + add,
- subtract, * multiply and / divide.
A pocket calculator
Python is a great calculator. Try your own sums, like 365 * 24.
Notice that / always gives a float, even when the
result is a whole number: 10 / 2 is 5.0. And any
math that involves a float produces a float.
Integers can be as big as you like. For readability you
may write underscores in long numbers:
1_000_000 is one million.
Types of results
** means "to the power of". Python handles huge integers without breaking a sweat.
What does this print?
What does this print?
Snack run
A sandwich costs 3.5 and you buy 4 of them.
Compute the cost and store it in total.
Use the price and quantity variables rather
than typing the answer.
Test average
Compute the average of the three scores (add them
up, then divide by 3) and store it in average.