Variables
6 min · Python
Store values in named boxes called variables, then reuse them.
Enemy 1 of 5
A variable is a name that holds a value, like a labeled box you can look inside later. Instead of retyping a value every time you need it, you give it a name once and let the name do the work. This matters more than it sounds: real programs juggle dozens or hundreds of values — a player's score, a user's name, a running total — and referring to them by name instead of by their raw value is what keeps code readable and correct.
You create a variable with an equals sign: the name goes on the left, the value goes on the right. It helps to read = out loud as "gets set to" rather than "equals" — in math, equals means both sides are the same forever, but in code, = is an action: take the value on the right and store it under the name on the left, replacing whatever was there before.
Once a value is stored, you can use the name anywhere instead of repeating the value. Run this to see Python remember the name and print it back.
Stuck? Ask Rena
Your AI tutor that gives assistance.
Asking Rena in lessons is on Ultimate.