Assignment: Putting a Value Under a Name
A variable is a name that points at a value. You make one
by writing the name, a single =, and the value:
player_name = "Rookie"
level = 1
xp = 0
Nothing is printed. Assignment is silent — it stores something and moves
on. From that point the name works anywhere the value would:
print(level) shows 1.
Read = as "gets", never as "equals"
x = 5 is not a claim that x and 5 are the same. It is an
instruction: x gets 5. Python works out the right-hand side
first, then attaches the name on the left to the result. Hold on to that
reading — it is what makes the line score = score + 10
sensible instead of mathematically impossible.
Repeating the value
print(4.25) in six places. Change the price and you have six edits and one you will miss.
Naming it once
unit_price = 4.25, then use the name everywhere. One edit changes all six.
Quick check
What does the line total = 3 * 4 leave stored under total?