Variables: Storing Things

Python for Absolute Beginners · Lesson 4

What you’ll learn

1 / 13

A variable is a labeled box

2 / 13

Storing text and a number

name = "Mia"
age = 9
print(name)
print(age)

Output:
Mia
9

name holds the text "Mia", and age holds the number 9. print(name) prints the value stored under that name — not the word "name". The same name works as many times as you like — print("Hello,", name) prints Hello, Mia again.

3 / 13

The quotes rule, again

4 / 13

Changing a value

5 / 13

Updating a score

score = 0
print(score)
score = 10
print(score)
score = score + 5
print(score)

Output:
0
10
15

Read the last line as: take the current value of score (10), add 5, and store the result (15) back in score.

6 / 13

Naming rules

7 / 13

Good names, bad names

8 / 13

Name versus string

name = "Mia"
print(name)
print("name")

Output:
Mia
name

print(name) prints the value stored under the name. print("name") prints the word itself, because quotes mean “this is text.”

9 / 13

Hands-on exercise

10 / 13

Key takeaways

11 / 13

Take the quiz

Take the Lesson 4 quiz — 5 quick questions to check what you learned.

12 / 13

Next lesson

Numbers and Arithmetic

13 / 13

Press play on any slide and the lesson plays on by itself from there. You can still click Next or click a slide to move on.