1.1 Types of data

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

1.1 Types of data

Computers work with different types of data. Knowing the main types helps you write code that does what you want.

The main types

Numbers

You can use them in maths: 2 + 3, 10 / 4, 3 * 5.

Strings

Strings are text. In Python you put them in quotes (single or double):

"hello"
'coding club'
"I'm learning Python"

Booleans

Booleans are either True or False. They are used for yes/no decisions. In Python the capital T and F matter.

True
False

Checking the type

You can see what type something is with type():

type(42)        # <class 'int'>
type(3.14)      # <class 'float'>
type("hello")   # <class 'str'>
type(True)      # <class 'bool'>

Mini project: About you

Write a short program that prints your name (as a string) and your age (as a number). Use print() like this:

print("My name is Alex")
print(12)

Try printing a sentence that uses both text and a number (you can pass several things to print separated by commas).


Next: 1.2 Variables — storing values so we can use them again.