A Name Bound to a Value
A variable is a name bound to a value, and every value carries a type — int, float, str, or bool — that fixes what can be done with it. · 10 min
A program needs to remember things: a score, a name, a price. It does that with a variable — a name you attach to a value. You write score = 5, and from then on the name score stands for 5. The name is convenient, but the value is what matters, and every value has a type: a whole number, a decimal, a piece of text, or a true/false answer. The type is not decoration. It decides what you are allowed to do with the value — and getting it wrong is one of the first errors you will meet.
Guess before you learn
A program runs score = 5, then on the next line score = 8. After both lines, what is the value of score?
The second line rebinds the name: score now stands for 8, and the old 5 is simply forgotten. If you guessed 13, keep that mark — assignment can look like it adds, but = replaces the value, it does not combine values.
9–12
3–5
A variable is a name bound to a value. When you write age = 12, Python stores 12 and lets the name age stand for it everywhere after. Change it with age = 13 and the name now points at the new value; the old one is forgotten. Every value also has a type. 12 is an int — a whole number. 3.5 is a float — a number with a decimal point. "cat" is a str — text, always in quotes. True and False are bool values — yes or no. The type decides what works: you can add two ints, but you cannot add a number to a word.
6–8
Assignment binds a name to a value: x = 5 makes x refer to 5. The single = is not the word 'equals' — it means store the value on the right under the name on the left. Re-assigning, x = 8, repoints the name; nothing about the first value lingers. Every value carries a type that fixes its behaviour: int (whole numbers), float (decimals), str (text in quotes), and bool (True or False). Type is a property of the value, not the name, so one name can hold an int now and a str later. Ask Python with type(x) and it will tell you which type a value is.
9–12
A variable is a binding between a name and a value; assignment count = 0 creates or updates that binding, and every later use of count looks up whatever value it currently holds. The right side is evaluated first, then stored — which is why count = count + 1 makes sense: read the old value, add one, store it back under the same name. Each value has a type — int, float, str, bool — that determines which operations are legal and what they mean: + joins two strings but sums two ints. Python is dynamically typed: the name carries no type of its own, only whatever value it points to right now, so tracking types as you read is part of tracing.
K–2
A variable is a name for a value. Think of a name tag. You put the number 3 on a tag and call it coins. Now, when you say coins, everyone knows you mean 3.
Every value has a kind, called its type. 3 is a number. The word cat is text. True and False are yes-or-no answers. The type tells you what you can do with the value.
Undergrad
A variable is a name in an environment that maps identifiers to values; assignment updates that mapping. Python uses reference semantics over a dynamically typed value space: the name is untyped, and the object it references carries the type. x = 5 binds x to an int object; x = "five" rebinds it to a str object, and the int may be garbage-collected. Types are not annotations the programmer decorates code with — they are properties objects genuinely have at runtime, checked when an operation is attempted. This is why "3" + 5 raises a TypeError rather than guessing: the + operator dispatches on its operands' types and finds no consistent meaning for one str and one int.
Postgrad
In a dynamically typed language, values inhabit a universal domain tagged with runtime types, and operators are partial functions defined only on certain tag combinations; + : int × int → int and str × str → str are distinct overloads with no int × str case, hence the TypeError. A variable is an l-value — a cell in a store — and assignment is the state-updating command store[x] := eval(e, store). The subtlety students meet later, mutation and aliasing, follows from the fact that two names may bind the same object: identity (is) and equality (==) come apart precisely because names denote references into a shared heap, not the values themselves.
variable
A name bound to a value. After speed = 30, the name speed stands for 30 until you bind it to something else.
The type also explains why x = x + 1 is not a contradiction. The = is an instruction, not a claim. Python evaluates the right side first, using the current value of x, then stores the result back under the name x. Read the old value, compute, write the new one. That single pattern — read, change, store — is how every counter, total, and running score in this course will work.
Trace the value of price — the steps fade as you master them
price = 4. What value does price hold now?price = 4
price = price + 2. Read the old value (4), add 2, store it back. What does price hold now?price = 6
price = price * 3. Read the old value (6), multiply by 3, store it back. What does price hold now?price = 18
Why is this true?
Why does x = x + 1 make sense, even though nothing can equal itself plus one?
Because = is not a claim of equality — it is an instruction. Python evaluates the right side first, x + 1, using the current value of x, then stores that result back under the name x. It reads the old value and writes a new one.
Note
Type errors slowing you down? The Atelier of Mind has drills for naming a value's type on sight.
Practice — new ink and old, interleaved
1.Put these three statements in the order Python runs them.
- print("first")
- print("second")
- print("third")
2.What number does print(6 + 6) show?
3.What is the type of the value False?
4.Say in your own words what a program is.
A program is an ordered list of statements a computer carries out exactly, one after another from top to bottom.
How close were you? Grade yourself honestly — it sets your review date.
5.In your own words: what does an assignment like name = value do?
It binds the name to the value: Python stores the value and lets the name stand for it until you assign the name something else.
How close were you? Grade yourself honestly — it sets your review date.
6.A program runs k = 7, then k = k - 2, then k = k * 2. What is k at the end?
7.Put these lines in the order they run, then say what prints. (Review from the last folio: statements run top to bottom.)
- coins = 0
- coins = coins + 5
- print(coins)