V0 = [0]
V1 = V0
V0[0] = 2
print(f"V0: {V0}")
print(f"V1: {V1}")
Asked
Active
Viewed 22 times
0

MattDMo
- 100,794
- 21
- 241
- 231
-
1V0 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