Your phone is full of data
Look at your phone. It shows the time. It shows your battery. It shows your name.
Some of it is a number. Some of it is words. Some of it is a yes or no.
A program must know which is which. The kind of value is called its data type. A data type is the kind of thing a value is.
Key words
| Word | What it means | Example |
|---|---|---|
| Data type | The kind of thing a value is. | integer, float, string, Boolean |
| Integer | A whole number with no decimal point. | 42 |
| Float | A number with a decimal point. | 2.50 |
| String | Text. It goes inside quote marks. | "hello" |
| Boolean | Only two values: True or False. | True |
| Variable | A name that holds a value. | goals = 3 |
| Decimal point | The dot in a number like 2.50. | 2.50 |
The cells students fill in are left blank in this preview.
Whole numbers: integers
An integer is a whole number. It has no decimal point.
Use an integer to count things. Your team scored 3 goals. The bus has 40 seats. You cannot score 2.5 goals, so goals are integers.
Try it: an integer
goals = 3
print(goals)
print(type(goals))
# Change 3 to 5 and press Run again.
Numbers with a point: floats
A float is a number with a decimal point.
Use a float for money, height and weight. A bus ticket costs 2.50. Your height is 1.75 metres. Both are floats.
Try it: a float
fare = 2.5
print(fare)
print(type(fare))
print(fare * 2)
Use a dot
data-callouts.tip.label
Python uses a dot, not a comma. Write 2.5, not 2,5. Python also prints 5.0 for two tickets. That is still a float.
Quick check: integer or float?
Have a go
Quick check: integer or float?
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
Text: strings
A string is text. Put it inside quote marks.
"Messi" is a string. So is "Leeds". A phone number is also a string, because you never add two phone numbers together. A bus route like "5A" is a string too.