← All lessons

Lesson 2 of 18 · about 12 minutes

Variables and Types 📦

A variable is a labelled box that stores a value. You create one with the equals sign.

name = "Ada"
age = 36
height = 1.68
is_coder = True

The four basic types

str for text, int for whole numbers, float for decimals and bool for True or False. Check any value's type with type(value).

Changing types

age_text = "36"
age = int(age_text)      # "36" becomes 36
price = float("9.99")    # text becomes a decimal
label = str(42)          # number becomes text
⚠️ "3" + 4 is an error: Python will not add text to a number. Convert first.

Naming rules

Use lowercase words joined by underscores: total_score, user_name. Names cannot start with a digit and cannot contain spaces.

Your challenge

Create a variable city holding "Hull" and a variable year holding 2026. Print them on one line separated by a space, then print the type of year.