📦 Variable
4th Grade 💻 Coding
A variable is a named spot in the computer’s memory that holds a value — a number, some text or true/false — that you can read and change while the program runs.
You can picture a variable as a box with a label: the label is the name (for example score), and what’s inside is the value (for example 10). In Python you create a variable with an assignment: score = 0. In Scratch you click “Make a Variable” and use the “set … to” and “change … by” blocks.
Give a variable a name that explains what’s in it: lives is better than x. In Python a name can’t start with a digit, can’t contain spaces, and Score and score are two different variables. The values in all the variables together describe the program’s “state” at any moment.
For example
- In a game:
lives = 3, and every time you get hit,lives = lives - 1. - A weather app has a variable
citywith the value "Denver" and a variabletempwith the value 88. - In a catch-the-apple game you need variables for the score, the number of lives and how fast the apples fall.
📌 Remember: Variable = box + label. The name stays; what’s inside can change.
Quick quiz
What is a variable?
Which variable name is clearer?
In Python, are Score and score the same variable?