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

Free lesson

6.4 (1 of 2): The seven common 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.

45 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

The school trip form

Your class is going on a trip. The booking form asks for six things.

Name. Age. Price paid. Has the form been signed? Date of the trip. A photo of the student.

Each one is a different kind of thing. You cannot add two names. You cannot sign a price. A computer must know the kind of each one. Today you learn the seven kinds.

Key words

WordWhat it meansExample
Data typeThe kind of a value, which says what you can do with it.integer, string, date
IntegerA whole number with no decimal point.16
RealA number with a decimal point.12.50
FloatThe Python name for a real number.1.75
CharacterOne single letter, digit or symbol."S"
StringA line of characters, used for text."Sam Brown"
BooleanOnly two values: True or False.True
DateA day in the calendar.14 June 2027
DatabaseAn organised store of data.The trip bookings
BlobA big lump of data kept whole (binary large object).photo.jpg

The cells students fill in are left blank in this preview.

The seven types on the trip form

Data typeWhat it holdsTrip form example
IntegerA whole numberAge: 16, seats booked: 32
Real (float)A number with a decimal pointPrice paid: 12.50
CharacterOne letter or symbolGroup letter: B
StringTextName: Sam Brown
BooleanTrue or FalseForm signed: True
DateA day in the calendarTrip date: 14 June 2027
BlobA big filePhoto of the student

The cells students fill in are left blank in this preview.

Try it: integer and real

Code: python
seats = 50
booked = 32
price = 12.5

print(seats - booked, type(seats - booked))
print(price * booked, type(price * booked))

# Change booked to 40 and run it again.

Make a free account to save your work and track your progress.

Quick check: integer or real?

Have a go

Quick check: integer or real?

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

Characters and strings

A character is one single letter, digit or symbol. "S" is a character.

A string is a line of characters. "Sam Brown" is a string. Python has no separate character type. It uses a string of length 1.

Try it: characters and strings

Code: python
name = "Sam Brown"
print(name)
print(name[0])
print(len(name))

# name[0] is the first character.
# Change the name and run it again.

Make a free account to save your work and track your progress.

A phone number is a string

Warning

Many people think a phone number is an integer because it holds digits. Use an integer only when you do sums with the value. You never add phone numbers. An integer also loses the zero at the start: 07700 becomes 7700. So store a phone number or a student number as a string.

Boolean, date and blob

A Boolean is True or False. Use it for yes or no questions, such as "form signed?".

A date is a day in the calendar. Use a date type, not a string, because the computer can then count the days to the trip.

A blob is a big lump of data, such as a photo. A database keeps it as one object. You do not read the inside of it as text.

Try it: dates and Booleans

Code: python
import datetime

trip = datetime.date(2027, 6, 14)
today = datetime.date(2027, 6, 1)

print(trip)
print(trip - today)
print(trip > today)

# The last line is a Boolean.
# Change today to the 20th of June and run it again.

Make a free account to save your work and track your progress.

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.

Which type is it?

A flowchart starting at "Look at the value": "A big file, such as a photo?" yes gives "Blob"; no leads to "Only True or False?", where yes gives "Boolean"; no leads to "A day in the calendar?", where yes gives "Date"; no leads to "Will you do sums with it?"; if no, "One character only?" gives "Character" for yes and "String" for no; if yes, "Has a decimal point?" gives "Real" for yes and "Integer" for no.A flowchart starting at "Look at the value": "A big file, such as a photo?" yes gives "Blob"; no leads to "Only True or False?", where yes gives "Boolean"; no leads to "A day in the calendar?", where yes gives "Date"; no leads to "Will you do sums with it?"; if no, "One character only?" gives "Character" for yes and "String" for no; if yes, "Has a decimal point?" gives "Real" for yes and "Integer" for no.

Watch: the seven common data types

Press Play on the short film below. It starts with the school trip form. Then it shows the seven types and ends with a myth.

Film: the seven common data types

The seven common data types

Every scene, as text

  1. The school trip form. The booking form asks for six things. You cannot add two names. You cannot sign a price. A computer must know the kind of each one.
  2. The seven types on the trip form. Integer: age 16. Real (float): price paid. Character: group letter B. String: name Sam Brown. Boolean: form signed, True. Date: 14 June 2027. Blob: photo of the student.
  3. Characters and strings. "S" is a character (holds: one letter, digit or symbol). "Sam Brown" is a string (holds: a line of characters). Python has no separate character type: it uses a string of length 1.
  4. Boolean, date and blob. Form signed? True (holds: True or False). 14 June 2027 − 1 June 2027 = 13 days (so: count the days to the trip). A photo, kept as one object (holds: a big lump of data).
  5. Myth (false): phone numbers are integers. A phone number holds digits. That is not true: you never add phone numbers. Use an integer only when you do sums with the value. An integer loses the zero at the start: 07700 becomes 7700. "07700 900123" is a string (so: phone and student numbers are strings).

Your turn: the trip form

Fill in the five functions for the trip form. Use the right type for each answer. The tests check the type as well as the value. Press Run Tests to check.

Code: python
import datetime


def seats_left(seats, booked):
    # Whole numbers. Give back how many seats are free.
    return None


def trip_cost(price, students):
    # price is a number with a decimal point, such as 12.50.
    # Give back the cost for all students. It must be a float.
    return None


def initial(name):
    # Give back the first character of the name, such as "S" for "Sam".
    return None


def is_paid(paid, price):
    # Give back True if the student paid the full price or more. Otherwise False.
    return None


def trip_date(day, month, year):
    # Give back a real date, not text.
    # Hint: datetime.date(year, month, day)
    return None

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.

Final check

Have a go

Final check

5 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

Seven types: integer, real, character, string, Boolean, date, blob. Ask: Is it a number? Will I do sums with it? Is it a day? Is it a big file?

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.