The idea
Think of a label on an item in the case file. The label clues lets you refer to its current value later. In clues = clues + 1, Python first reads the old value, adds one and then binds the name to the result. This is a step in time, not an algebra equation that must be true forever. The current values a program remembers are part of its state.
A tiny experiment
clues = 2
old_count = clues
clues = clues + 1
print(clues)
print(old_count)Reveal the expected output
3 2
Read it one step at a time
- clues begins with the integer 2. Integer means a whole number.
- old_count also refers to 2. It is not a formula that will automatically follow clues.
- After reassignment, clues refers to 3. old_count still refers to 2.
Make one change
Add another clues = clues + 1 before the prints. What should old_count show?
Check your thinking
clues becomes 4 and old_count remains 2.
Keep following the trail
Sources & further reading
Companion notes for Coding Adventure by James Colby. Historical claims link to their sources; the examples are written for this learning trail.