Today you will learn to:
By the end, you will be able to store data and work with it.
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
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
In Python, there are different data types. They tell Python what kind of data is being stored.
Integers are whole numbers without decimals.
age = 20
points = 150
year = 2024
Floats are numbers with decimal points.
price = 9.99
temperature = 21.5
weight = 70.3
Strings are texts and are always enclosed in quotes.
name = "Max"
city = "Berlin"
movie = "Matrix"
Important:
Without quotes, Python thinks it’s a variable.
Boolean can only have two possible values:
active = True
game_started = False
has_ticket = True
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'>
name = "Anna"
age = 25
print("Hello", name)
print("You are", age, "years old")
Output:
Hello Anna
You are 25 years old
The value of a variable can change.
points = 10
points = 20
Now the value is:
20
This is called overwriting a variable.
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.
Create variables for:
Example structure:
book = "Harry Potter"
pages = 500
read = True
Then display the variables:
print(book)
print(pages)
print(read)