Exerpad
🔥1
10 XP
Lv.1 Beginner
Log In

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

Types of Values

Strings — text inside quotes:

python
color = "blue"
greeting = 'Hello!'

Integers — whole numbers:

python
score = 100
lives = 3

Booleans — True or False:

python
is_happy = True
is_raining = False

Using Variables

You can use variables in print():

python
name = "Alex"
print(name)

Output:

text
Alex

You can print variables with text:

python
name = "Alex"
print("Hello,", name)

Output:

text
Hello, Alex

Changing Variables

You can change what's inside a variable:

python
score = 0
print(score)
score = 100
print(score)

Output:

text
0
100

The old value is replaced by the new one.