A program that only prints fixed text is a notice board. Programs become useful when they work with values that can change — a score, a name, a count, a price — and Python's way of holding a value is the variable: a name attached to a value, which the program can then use, change, and use again. That one mechanism is the program's memory. Everything a program knows while it runs lives in variables, and tracing a program means nothing more or less than following those names and their current values as each statement changes them.
The difficulty is that the central symbol looks familiar. It is not.
The equals sign that is not an equals sign
Consider three lines:
`score = 10`, then `print(score)`, then `score = score + 5`, then `print(score)` again. Run the program and it prints 10, then 15.
Read the third line slowly, because beginners misread it for months and the misreading poisons everything after. The `=` sign in Python is not the equals sign of school mathematics. In mathematics, `score = score + 5` would be a claim, and a false one. In Python it is an instruction: work out the right-hand side, then attach the left-hand name to the result. So the line means: take the value `score` currently holds (10), add 5 (giving 15), and re-attach the name `score` to 15. The old value is gone, replaced.
Attaching a name to a value is called assignment, and the line that does it is an assignment statement. Once that reading is settled, a whole class of programs stops looking like algebra and starts reading as a sequence of instructions, which is what a program is.
Tracing is the core skill
Practice the trace on paper, until it is dull:
`chairs = 8`. Line one: `chairs` holds 8. Next, `chairs = chairs + 4`: work out the right-hand side, 8 + 4, so `chairs` now holds 12. Next, `chairs = chairs - 3`: 12 − 3, so `chairs` now holds 9. Finally `print(chairs)` prints 9.
If you predicted 9 before reading the answer, you have the core skill of this concept. If you predicted anything else, reread the trace — every later concept assumes you can do this without effort. Tracing is not a study exercise added to programming. It is programming, read from the author's side: following the state is how you know what the program will do before you run it, and why it did what it did after.
When a program ends, its variables vanish. The values that must survive need another home, which is a later problem. While the program runs, the state is all there is.
Values come in kinds, and the kind decides what a value can do
Four kinds carry the foundations. Integers are whole numbers: `7`, `0`, `-3`. Floating-point numbers carry a decimal part: `3.5`, `0.25`, and they are the right kind for measurements and money-like quantities in exercises. Strings are text, always in quotation marks: `"Ana"`, `"left-handed"`, even `"42"` — which is text that looks like a number and behaves like text. Booleans are the two truth values, `True` and `False`, spelled with capital letters; they look humble and they run every decision and loop that follows.
Python works out a value's kind from how you wrote it: `42` is an integer, `42.0` is a float, `"42"` is a string. Ask a value its kind with `type` when in doubt — `type(42)` reports the integer kind. This matters practically, not pedantically: handing a tool the wrong kind of value is the beginner's most common accident, and error messages name kinds constantly. The programmer who reads `42` and `"42"` as the same thing will meet that accident early and often.
Names have rules, and customs that matter as much
The rules: a name may contain letters, digits, and underscores, may not begin with a digit, and may not be one of Python's reserved words. `print` is taken; `for`, `while`, and `if` and their kin are taken too.
The customs matter as much. Use lowercase words joined by underscores — `seats_booked`, not `SeatsBooked` — and choose names that say what the value is. `x` and `tmp` are legal and nearly useless; six lines later, neither you nor anyone else remembers what they hold. A variable name is a promise to every future reader — including you, next week — about what the value means. Keep the promise cheap to keep: name it once, name it well.
Assignment copies a value at a moment in time
One last trap is set by the assignment mechanism itself. Two names can be attached in sequence, and a beginner expects them to stay linked. They do not:
`cups = 6`, then `mugs = cups`, then `cups = 10`, then `print(mugs)`. It prints 6.
`mugs = cups` copied the value `cups` held at that moment. Re-attaching `cups` to 10 afterward does not reach back and change the copy. Assignment copies a value at a moment in time. Hold that sentence and a whole family of future bugs never happens.
This corrects the common account: "A variable is a box the value lives in, and `a = b` means the two are the same thing from then on." A variable is a name attached to a value. Attach the name to something else later and only that name moves. Programs that surprise their authors almost always surprise them here first: a value the author thought was linked was only ever copied. Learn to trace names, respect kinds, and name things for the reader you will be next week, and the rest of the language has solid ground to stand on.
Experience it, don’t just read about it
A variable is a name attached to a value, and assignment copies that value at a moment in time rather than linking two names is Concept 2 of First Code in Python: Programming Foundations Built Step by Step (Course No. 331), from Cognosco Learning, a learning company powered by AI. The course builds the wider foundations beyond this distinction — Numbers and Expressions — Making the Machine Calculate, Decisions — Branching with Comparisons and Logic, and Functions — Naming a Move So You Can Use It Twice — each worked through with an Agentic Socratic AI coach, one learner at a time. Try a Free Preview at cognoscolearning.com.
Navigate your own course.
© 2026 Cognosco Learning. All rights reserved.