Variables
Prerequisites: What is programming?
A variable is a named place to store a value so you can use it again later.
Real-world analogy: a variable is like a labeled box. You write a
label on it ("age"), put something inside (25), and later you can
look inside the box just by reading its label — or put something
different inside.
Most languages share the same shape for creating one:
age = 25
name = "Ada"
Once a value is stored in a variable, you can use the variable's name anywhere you'd use the value itself, and update it later as the program runs.
Common mistakes
- Using a variable before giving it a value.
- Confusing a variable's name with its value — the name
("age") is just a label; the value (
25) is what's stored.