โ† Back to Python Course
๐Ÿ Python Playgroundยท15 minยทBeginner
๐Ÿ“ฆ

Variables

Storing stuff in named boxes

Learn how to store information in variables โ€” named boxes that hold your data until you need it.

๐Ÿ“–

What we are learning

A variable is like a labeled box where you store something. You put a value inside, give the box a name, and later you can look inside the box to see what is there. Variables let your program remember things!

๐Ÿ’ก Think of it like this:

Imagine you have a bunch of shoe boxes. You write "sneakers" on one, "sandals" on another. Later, when you want your sneakers, you just look for the box labeled "sneakers". Variables work the same way!

๐ŸŒŸ

Why it matters

Without variables, your program would forget everything. Variables let you store a player's name, a game score, a password โ€” anything you need to remember.

Where you see this in real life:

  • โœ“Games store your score and player name in variables
  • โœ“Apps store your username and settings in variables
  • โœ“Calculators store the numbers you type in variables
๐ŸŽฏ

By the end, you can:

  • 1.Create a variable and store a value in it
  • 2.Use variables in print statements
  • 3.Change the value of a variable
๐Ÿ”ค

New words

variableassignmentvaluename
๐Ÿ
If you had three magic boxes that could hold anything, what would you put in them and what would you label them?
๐Ÿค“

Fun Fact!

In Python, you can name a variable almost anything โ€” even "pizza" or "dinosaur" โ€” as long as it has no spaces!

๐Ÿ“ฆ What is a Variable?

A variable is a labeled box that stores information. You give the box a name, put something inside, and later you can look inside to see what is there.

To create a variable, you write the name, an equals sign, and the value. Like this: name = "Alex"

โœจ Create Your First Variable

๐ŸStore and print a variable
main.py
โ— Output
The variable 'name' stores the text 'Alex'. print() shows it!

๐Ÿ’ก Try changing "Alex" to your own name!

๐Ÿ”„ Change the Value

Variables are called "variable" because they can CHANGE! You can update the value whenever you want.

๐ŸVariables can change!
main.py
โ— Output
Click โ–ถ Run to see the output!

๐Ÿท๏ธ Naming Variables

Rules for naming variables:

  • โœ… Use letters, numbers, and underscores
  • โœ… Names can not have spaces
  • โœ… Names can not start with a number
  • โœ… Use snake_case (words separated by _)

โœ… Good names

player_name
age
favorite_color
score_2

โŒ Bad names

player name
2nd_score
favorite-color
class

๐Ÿ
Try creating variables for your name, age, and favorite food. Then print them all!
๐Ÿง 

Quick Quiz!

+10 XP

Which of these is a valid variable name in Python?

๐Ÿ
Finished the lesson? Click the button to mark it complete and earn XP!