Live Engine
Select Topic
easyAdvanced Semantics
A developer notices this surprising behavior in Python and asks why b changes when only a is modified:
Code
a = [1, 2, 3]
b = a
a.append(4)
print(b) # [1, 2, 3, 4] — why?