Guide Python Intermediate

6.4 Assignment Operations

Why all assignment in Python is reference assignment, why there's no true separate value-assignment mechanism, and how that plays out differently for mutable versus immutable objects.

2 min read

Reference Assignment

b = a makes b point at the exact same object a does — no data is copied, as covered in 6.2 Objects and Variable References.

There’s No Separate “Value Assignment”

What Is It?

Python doesn’t truly have a separate “value assignment” the way some languages do — all assignment is reference assignment.

Why Does It Matter?

For an immutable value like an int, this distinction rarely matters in practice, because the value itself can’t be mutated — any operation that looks like a change actually rebinds the name to a brand-new object.

>>> c = 5
>>> d = c          # d references the same int object as c
>>> d += 1         # this REBINDS d to a new object -- doesn't mutate the int
>>> c, d
(5, 6)

Effects on Mutable Objects

How Is It Used?

The consequence of reference assignment becomes visible specifically when the shared object is mutable — append() mutates the object in place, so every name referencing it sees the change:

>>> a = [1, 2]
>>> b = a
>>> b.append(3)    # mutates the shared object in place
>>> a, b
([1, 2, 3], [1, 2, 3])

Rebind vs Mutate

OperationWhat Actually HappensVisible Through Other References?
d += 1 (int)Rebinds d to a new int objectNo — other names still point at the old value
b.append(3) (list)Mutates the existing object in placeYes — every reference to it sees the change
t = t + (3,) (tuple)Creates a brand-new tuple, rebinds tNo — see 5.9 Mutable vs Immutable Types

Quick Interview Answer

“Python has no separate ‘value assignment’ mechanism — every assignment binds a name to an object reference. d = c; d += 1 looks like it mutates c’s value, but for an immutable int it actually rebinds d to a brand-new object, leaving c untouched. The same b = a; b.append(3) pattern on a mutable list mutates the one shared object in place, so the change is visible through both a and b. The difference isn’t the assignment — it’s whether the object being pointed at is mutable.”

Common Mistakes

  • Assuming += always mutates in place — for immutable types (int, str, tuple) it rebinds; for mutable types (list, via __iadd__) it does mutate in place, which is a subtle and commonly missed distinction.
  • Forgetting that reassigning a variable never affects other names that shared its old object — only mutation does.

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form