University of Free Knowledge
QA 76.73 · fol. 2

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 DEPTH DIAL — the same idea, younger or deeper
9–12

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 typeint, 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.

variable

A name bound to a value. After speed = 30, the name speed stands for 30 until you bind it to something else.

VALUETYPEWHAT IT IS42inta whole number3.14floata number with a decimal point"cat"strtext, always in quotesTrueboolone of two answers: True or False
PLATE I Four everyday types — the type travels with the value, not with the name.

Ink That Thinks — guess first; the answer draws itself.
This program adds coins one line at a time. Before reading on, place a point for the value of coins after each line runs. coins = 0 coins = coins + 3 coins = coins + 3 coins = coins + 3

01234502.557.510after line numbervalue of coins
Tap to place each point.
PLATE II A counter growing by 3 — guess in graphite, truth in ink.
Retrieval Gate — answer before you continue 0 / 4

1.What is the type of the value 3.5?

2.Match each value to its type.

42
3.14
"hi"
True

3.A program runs x = 10, then x = x - 4. What is the value of x after both lines?

4.What is the type of "7" — the 7 written inside quotes?

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.

evaluate the right sidestore the resultthe name now points to it
PLATE III Assignment, in order: compute the value first, then bind the name to it.

Trace the value of price — the steps fade as you master them

1
Line 1: price = 4. What value does price hold now?
price = 4
2
Line 2: price = price + 2. Read the old value (4), add 2, store it back. What does price hold now?
price = 6
3
Line 3: 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.

Retrieval Gate — answer before you continue 0 / 4

1.What does the single = do in total = 5?

2.A program runs n = 2, then n = n * 5, then n = n + 1. What is the value of n at the end?

3.Why does "3" + 5 cause an error?

4.Without looking back: name the four basic types and give one example value for each.

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.

  1. print("first")
  2. print("second")
  3. 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.

5.In your own words: what does an assignment like name = value do?

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.)

  1. coins = 0
  2. coins = coins + 5
  3. print(coins)
The Call Slip — search everything Ctrl·K / ⌘K