Lesson 1
Variables
A variable is a name for a value. Think of it as a labelled box: you put something in, and later you can look at it or swap it for something else.
name = "Ada"
age = 12- The
=means "put this value in the box". It is not the same as "equals" in math. - Text goes in quotes:
"Ada". Numbers do not:12. - Names use small letters and underscores:
favorite_game, notFavorite Game. - To put a variable into text, use an f-string:
f"Hi {name}".
Lesson 1 · Try it
Play with variables
Press Run, then try to:
- Change the name and the age.
- Add a variable
favorite_gameand print it. - What happens if you remove the quotes around
"Ada"?
Press ▶ Run to see what happens.
Lesson 1 · Exercise
Meet the pirate
Make three variables: pirate_name, ship and gold.
Then print one sentence that uses all three, for example: Redbeard sails the Black Pearl with 100 gold coins.
Press ▶ Run to see what happens.
💡 Need a hint?
Replace each ... with a value. Text needs quotes, numbers do not. Inside the f-string, write the variable names in curly braces: {pirate_name}.
Lesson 1
Add it to your project
Open your learn-python project in Zed and make a new file called pirate.py.
Copy your exercise code into it and run it from the terminal:
uv run pirate.pyNotice how Zed colours the variable names and the text differently. That helps you spot missing quotes.