1. Concept library
  2. Python Foundations
  3. Module 1: Values, variables and types

Concept

Variables and assignment

A variable is a name bound to a value, not a box that holds it. Assignment points a name at an object, and two names can point at the same one.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what assignment does to a name, using the idea of a name pointing at an object
  2. Predict what two names bound to the same list show after a change through one of them
  3. Write code that copies a list on purpose instead of sharing it

In practice

A few lines that show Variables and assignment doing its job.

Python
scores = [70, 85]
backup = scores        # same list, second name
backup.append(90)
print(scores)          # [70, 85, 90]

count = 1
count = count + 1      # rebinds count to a new int, 2

The common mistake

Watch for

Expecting backup = scores to copy the list. Both names refer to one list, so a change through either name shows up in both.

What to know first

Your roadmap puts these before Variables and assignment, unless you already know them.

How it stays learned

Once a session shows you understand Variables and assignment, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Variables and assignment.

Previous in the module← Numbers and strings
Next in the moduleType conversion →