Reassignment: Values Change

Variables can be reassigned, given a new value that replaces the old one. The container keeps its name; its contents change. The computer only remembers the most recent assignment.

EXAMPLE
loading editor…
YOUR TURN
Your turn → The JavaScript tab hides a saboteur line. Delete it, run both tabs, and confirm both print 25.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

One subtlety that trips everyone up once: copying a variable copies its current value, not a live link.

EXAMPLE
loading editor…
YOUR TURN
Your turn → Make a variable called first that holds your first name, copy it into a variable called original, then change first to a nickname. Print both to see that original kept the first value.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Constants and Good Names →
← Back