0
Please help understand this code
I don't understand the output of this code : A = [1,2,3,[6,7,8,9]] B = A[:] A[1] = 4 A[3][1] = 0 print(B) why is it [1,2,3,[6,0,8,9]] and not [1,4,3,[6,0,8,9]] ?
3 Answers
+ 1
B is a copy of A. not a reference
you can make it a copy by removing the [:]
0
Ok but why the list inside A has changed ?
0
...cause you changed the values...