Exerpad
Lesson · Chapter: Variables+10 XP for reading

What are Variables?

A variable is like a labeled box that stores a value. You give the box a name, and you can put something inside it.

Creating Variables

Use = to store a value in a variable:

python
name = "Alex"
age = 10
Output
Press Run to see the output.

Types of Values

Strings — text inside quotes:

python
color = "blue"
greeting = 'Hello!'
Output
Press Run to see the output.

Integers — whole numbers:

python
score = 100
lives = 3
Output
Press Run to see the output.

Booleans — True or False:

python
is_happy = True
is_raining = False
Output
Press Run to see the output.

Using Variables

You can use variables in print():

python
name = "Alex"
print(name)
Output
Press Run to see the output.

Output:

Alex

You can print variables with text:

python
name = "Alex"
print("Hello,", name)
Output
Press Run to see the output.

Output:

Hello, Alex

Changing Variables

You can change what's inside a variable:

python
score = 0
print(score)
score = 100
print(score)
Output
Press Run to see the output.

Output:

0
100

The old value is replaced by the new one.