Python Level 2: Variables & Data Types

Goal of this Level

Today you will learn to:

By the end, you will be able to store data and work with it.

Step 1: What is a Variable?

A variable is like a box where you can store information.

Examples of things you can store:


age = 20

Here’s what happens:

Python now remembers:


age = 20

Step 2: Creating Variables

You can create variables for many things.


name = "Max"
age = 20
city = "Berlin"

Then you can display them:


print(name)
print(age)

Output could be:


Max
20

Step 3: Main Data Types

In Python, there are different data types. They tell Python what kind of data is being stored.

1. Integer (int) – Whole numbers

Integers are whole numbers without decimals.


age = 20
points = 150
year = 2024

2. Float – Decimal numbers

Floats are numbers with decimal points.


price = 9.99
temperature = 21.5
weight = 70.3

3. String (str) – Text

Strings are texts and are always enclosed in quotes.


name = "Max"
city = "Berlin"
movie = "Matrix"

Important:

Without quotes, Python thinks it’s a variable.

4. Boolean (bool) – True or False

Boolean can only have two possible values:


active = True
game_started = False
has_ticket = True

Step 4: Check Data Type

Sometimes you want to know the type of a variable.

For that, you use type().


age = 20

print(type(age))

Output:


<class 'int'>

More examples:


name = "Max"

print(type(name))

Output:


<class 'str'>

Step 5: Using Multiple Variables Together


name = "Anna"
age = 25

print("Hello", name)
print("You are", age, "years old")

Output:


Hello Anna
You are 25 years old

Step 6: Changing Variables

The value of a variable can change.


points = 10
points = 20

Now the value is:


20

This is called overwriting a variable.

Practice Example


name = "Max"      # String
age = 20          # Integer
price = 9.99      # Float
active = True     # Boolean

print(type(age))

The program shows the data type of the variable.

Task

Create variables for:

Example structure:


book = "Harry Potter"
pages = 500
read = True

Then display the variables:


print(book)
print(pages)
print(read)