Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

2.1: Standard data types

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

40 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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

WordWhat it meansExample
Data typeThe kind of thing a value is.integer, float, string, Boolean
IntegerA whole number with no decimal point.42
FloatA number with a decimal point.2.50
StringText. It goes inside quote marks."hello"
BooleanOnly two values: True or False.True
VariableA name that holds a value.goals = 3
Decimal pointThe 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

  1. Every value has a data type. Here are four: an integer, a float, a string and a Boolean.
  2. An integer is a whole number, like 3 goals. 2.5 goals is not a whole number, so it is not an integer.
  3. 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.
  4. A string is text inside quote marks, like "Messi". A phone number is digits, but in quote marks it is text too.
  5. A Boolean is True or False. It answers a yes or no question. Is the phone charged? True.
  6. 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

Code: python
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

Code: python
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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

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.

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

Code: python
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

Code: python
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?

A flowchart asks three questions in order, is it text in quote marks, is it True or False, does it have a decimal point, and the first yes names String, Boolean or Float, while three noes mean Integer.

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.

Code: python
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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Remember

Important

Four data types: integer, float, string, Boolean. Ask two questions. Is it text? Does it have a decimal point?

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.