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.
Watch: four kinds of value
Press Play on the short film below. Watch the shape of each type: blocks, a point, beads in quote marks and a switch. At the end, watch what quote marks do to 5 + 5.
Film: four data types
Four data types
Every scene, as text
- Every value has a data type. Here are four: an integer, a float, a string and a Boolean.
- An integer is a whole number, like 3 goals. 2.5 goals is not a whole number, so it is not an integer.
- A float has a decimal point. 2.50 is 2, the point, then 50. Python uses a dot, not a comma. Two tickets: 2.50 + 2.50 = 5.0, still a float.
- A string is text inside quote marks, like "Messi". A phone number is digits, but in quote marks it is text too.
- A Boolean is True or False. It answers a yes or no question. Is the phone charged? True.
- Watch the quote marks. The numbers 5 + 5 make 10. The strings "5" + "5" join to make "55".
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.
Make a free account to save your work and track your progress.
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)
Make a free account to save your work and track your progress.
Use a dot
Tip
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 questionsText: 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.
Quote marks matter
Warning
The number 5 and the string "5" are not the same. Python adds the number 5 and 5 to make 10. It joins the strings "5" and "5" to make "55".
Try it: a string
team = "Leeds"
print(team)
print(type(team))
print(team + " United")
Make a free account to save your work and track your progress.
Yes or no: Booleans
A Boolean has only two values. They are True and False.
It answers a yes or no question. Is the phone charged? Is the bus late? Python writes them with a capital letter: True and False.
Try it: a Boolean
battery = 15
low_battery = battery < 20
print(low_battery)
print(type(low_battery))
# 15 is less than 20, so this is True.
# Change 15 to 80 and run it again.
Make a free account to save your work and track your progress.
Which data type is it?
Match the value to its type
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Your turn: the bus fare
A bus ticket costs 2.50. Fill in the three functions. The first finds the cost for a group. It must give back a float. The second says if a person is a child. Under 16 is a child. It gives back True or False. The third joins strings to make a label. Press Run Tests to check your work.
def total_fare(people, fare):
# people is a whole number. fare is a number with a decimal point.
# Give back the cost for the whole group.
return 0
def is_child(age):
# A child is under 16. Give back True or False.
return None
def ticket_label(name, route):
# Give back text like: Sam takes the 42 bus.
return ""
Make a free account to save your work, or press Start lab to work through the whole lesson.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Exit quiz
Have a go
Exit quiz
6 questionsRemember
Important
Four data types: integer, float, string, Boolean. Ask two questions. Is it text? Does it have a decimal point?