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]] ?

8th Aug 2020, 11:39 PM
A. Essabbere
A. Essabbere - avatar
3 Answers
+ 1
B is a copy of A. not a reference you can make it a copy by removing the [:]
8th Aug 2020, 11:57 PM
Randomocity
Randomocity - avatar
0
Ok but why the list inside A has changed ?
9th Aug 2020, 12:32 PM
A. Essabbere
A. Essabbere - avatar
0
...cause you changed the values...
9th Aug 2020, 2:43 PM
Randomocity
Randomocity - avatar