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
| Word | What it means | Example |
|---|---|---|
| Data type | The kind of a value, which says what you can do with it. | integer, string, date |
| Integer | A whole number with no decimal point. | 16 |
| Real | A number with a decimal point. | 12.50 |
| Float | The Python name for a real number. | 1.75 |
| Character | One single letter, digit or symbol. | "S" |
| String | A line of characters, used for text. | "Sam Brown" |
| Boolean | Only two values: True or False. | True |
| Date | A day in the calendar. | 14 June 2027 |
| Database | An organised store of data. | The trip bookings |
| Blob | A 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 type | What it holds | Trip form example |
|---|---|---|
| Integer | A whole number | Age: 16, seats booked: 32 |
| Real (float) | A number with a decimal point | Price paid: 12.50 |
| Character | One letter or symbol | Group letter: B |
| String | Text | Name: Sam Brown |
| Boolean | True or False | Form signed: True |
| Date | A day in the calendar | Trip date: 14 June 2027 |
| Blob | A big file | Photo of the student |
The cells students fill in are left blank in this preview.
Try it: integer and real
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 questionsCharacters 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
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
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?
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
- 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.
- 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.
- 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.
- 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).
- 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.
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 questionsRemember
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?