Python · Stage 1 · Storing Information · Lesson 9 of 50

Integers and Floats

Understand Python’s two beginner number types: whole and decimal numbers.

lives = 3
Line-by-line explanation
  1. lives is the variable name.
  2. = stores a value.
  3. 3 is an integer because it is whole.
temperature = 21.5
Line-by-line explanation
  1. temperature names the value.
  2. = stores it.
  3. 21.5 is a float because it has a decimal point.

Numbers are written without quote marks. Quotes would create text that only looks like a number.

print(3 + 2)
Line-by-line explanation
  1. 3 and 2 are integers.
  2. + asks Python to add them.
  3. print displays the result 5.

Computers store many decimal values as close approximations. You will learn the practical effect of that later; for now, use floats for ordinary measurements.

Tiny Practice: Store Two Numbers

Store an age as an integer and a height in metres as a float.

Starter template

age = 0
height = 0.0
Line-by-line explanation
  1. The first line needs a whole number.
  2. The second line needs a decimal number.
Hint
  1. Do not use quotes.
  2. Age normally has no decimal point.
  3. Metres normally use a decimal point.
Show Solution
age = 12
height = 1.55
Line-by-line explanation
  1. 12 is an integer.
  2. 1.55 is a float.
  3. Your values may be different.