aliasing

Having two or more names that refer to the same object, so a change made through one name shows up through the other.

In more detail

Assignment such as b = a never copies; it makes b another name for the same object. With immutable values that is harmless, but with a list or a graphics shape, changing b changes a too. Make a separate copy with clone(), list(a), a[:] or copy.copy when you need one.

Example

a = [1, 2]
b = a
b.append(3)
print(a)   # [1, 2, 3]

Related terms

Taught in

References

Certification courses