← Back to Education
Education digital-technologies year-9

Chapter 4 - Data Types

An introduction to strings, numbers, and boolean-style thinking through the Explorer build.

Published Updated Type lesson

Chapter 4 expands the program beyond plain text by introducing different kinds of values and what they are useful for.

Chapter Navigation

Chapter 4 — Not all information behaves the same
EXPLORER · v3 · learning how Python treats different kinds of information
Where we are now
Your console can now remember details about the mission and the system.

You stored the location, the day, and the system state at the top of the program, then used those values in the output.

Everything worked, and that might make it feel like all information is basically the same.

It is not.
A small question that changes everything
Look at this line from the previous chapter:

mission_day = 1

A very reasonable question to ask is:

What happens tomorrow?

If the mission continues, the day should increase.

That sounds simple, but it only works because mission_day is a number that Python can count.
Whole numbers are called ints
In Python, a whole number like 1, 2, or 42 is an int.

int is short for integer.

Because mission_day is an int, Python knows it can do maths with it.
Text behaves differently
Now look at this line:

mission_location = "Scrubby Creek"

This value is text.

In Python, text is called a string.

Strings can be printed and joined to other strings, but they cannot be counted or added to numbers.

Python treats strings and ints differently on purpose, because they represent different kinds of information.
Numbers with decimals
Not all numbers are whole numbers.

If you store something like a temperature, distance, or time, you often need decimals.

In Python, numbers with decimal points are called floats.

A float behaves like a number, but Python keeps track of the decimal part as well.
True or false values
Some information is not a number or text.

Sometimes something is either true or false.

In Python, these values are called booleans, or bool for short.

A boolean can only ever be True or False.
EXPLORER v3 (run this)
This version of the console now stores different kinds of information and uses them correctly.

Notice how each variable has a clear type and a clear purpose.
"""
EXPLORER v3 — Chapter 4

This version introduces different data types:
int, string, float, and bool.
"""

# =========================
# MISSION DETAILS
# =========================

mission_location = "Scrubby Creek"      # string
mission_day = 1                         # int
temperature_c = 23.5                    # float

# =========================
# SYSTEM STATE
# =========================

system_online = True                    # bool

# =========================
# CONSOLE OUTPUT
# =========================

print("=" * 44)
print("              EXPLORER CONSOLE              ")
print("=" * 44)

print(f"Location: {mission_location}")
print(f"Day: {mission_day}")
print(f"Temperature: {temperature_c} °C")
print()

print("System status:")
print(f"- Online: {system_online}")

print("=" * 44)
Change one value and observe
Change the mission day to a different number.

Change the temperature.

Change the system state to False.

Run the program each time and watch what changes.

The output changes, but the structure of the program stays stable. That is the goal.
Next time
Right now, all the information still lives inside the program.

In the next chapter, we will let the user provide information using input(), then deal with the new problems that creates.