Open JeppeDruedahl opened 5 years ago
Why is the first element of list A equal to zero when I run this code?
A
A = [1,2,3] B = A B[0] = 0 print(A[0])
The variable A is a reference to the list [1,2,3]. The second line, B = A, copies this reference, not the list itself. A and B therefore now refer to the same list.
[1,2,3]
B = A
B
Why is the first element of list
A
equal to zero when I run this code?