0
V0 = [0]
V1 = V0

V0[0] = 2

print(f"V0: {V0}")
print(f"V1: {V1}")
MattDMo
  • 96,286
  • 20
  • 232
  • 224
  • 1
    V0 and V1 hold the same reference to the value. –  Dec 16 '21 at 18:40
  • Python uses references, if you'd like a copy of V0, use `copy()` – mdf Dec 16 '21 at 18:42
  • Right. There is only one list in your program. That list happens to be bound to two names. This is one of the classic Python blunders. https://github.com/timrprobocom/documents/blob/main/UnderstandingPythonObjects.md – Tim Roberts Dec 16 '21 at 18:44

0 Answers0