Press ▶ Run to see what your program does.
Lesson 26: Variables: boxes with labels
Level 4, Python First Steps. Keep a value under a name, change it, and use it. The new word: variable. It follows lesson 25, Hello, Python! (print). Next comes lesson 27, Numbers and maths.
What the lesson explains
Boxes with labels. A variable keeps a value under a name.
name = "Sam". Put a value in the box, then use the name. On the card: name = "Sam"
What you do first
Your own box. Run it as it is. One way to write it: name = "Sam" / print(name). It prints: Sam.
The code on the screen
name = "Sam". The editor shows 2 lines: name = "Sam" / print(name). Run it, and it prints "Sam".
What is in the box?. The editor shows 3 lines: x = 5 / x = 7 / print(x). Run it, and it prints "7".
What you practise
Try it, "Your own box": Run it as it is. One way to write it: name = "Sam" / print(name). It prints: Sam. Then: Make pet and print it. One way to write it: pet = "cat" / print(pet). It prints: cat.
In your head, "What is in the box?": x = 5, then x = 7, then print(x). What does it print? The answer: "7".
Fix it, "NameError": Fix the name so it prints blue. The editor opens with: colour = "blue" / print(color). One way to write it: colour = "blue" / print(colour). It prints: blue.
What PlayBuddy and PlayType say
PlayType: "A variable is a box with a label. Put a value in, and use it later."
PlayBuddy: "The equals sign puts a value into the box. It works from right to left."
Help in every lesson
Everything happens on a pretend computer in your browser, so nothing touches your real files. PlayBuddy and PlayType stand beside the board, cheer you on and say when it is your turn.
A green ring shows where to click the first time. After that you do it on your own, and if you slip twice the ring comes back.
Stars
The lesson has 4 things to do. Up to one slip in ten gives three stars, up to one in four gives two, and finishing always gives at least one. Stars and progress are saved in this browser only; there is no account.
About DayOneCode
DayOneCode is an independent learning site, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic.