Lesson 2: Print and Variables

⏱ ~20 min Lesson 2 of 10 💚 Free

A variable is like a labeled box that stores a value. You name the box, put something inside it, and use it later. Variables are one of the most powerful tools in all of programming.

Key Concepts

Creating a Variable

In Python you create a variable with a single equals sign: name = 'Alex'. This creates a box called name and puts Alex inside it. No need for any special keyword!

Using Variables

Once created, you can use the variable anywhere. print(name) will display whatever is stored in the name box. If you change the value later, print() shows the new value.

Variable Names

Good variable names describe what they store. age, score, player_name are all great names. x and y work too but are harder to understand later. Use descriptive names!

🆕 Try It: Live Python

Change the values and see what happens!

✅ Check Your Understanding

1. What is a variable?

2. What does name = 'Alex' do?

3. Which is a good variable name?