0

Why a and b are not same?

a = [1,[1,2]] b= a[:] a[0] = 3 a[1][1] = 5 print(a) print(b) Output: [3,[1,5]] [1,[1,5]]

31st Aug 2021, 5:07 PM
Surya T
Surya T - avatar
1 ответ
+ 7
a[:] is shallow copying . Only reference for outer list is changed . Inner list [1, 2] is pointing to same reference . If you need to make both list same then just assign a to b, i.e. b=a.
31st Aug 2021, 5:15 PM
Abhay
Abhay - avatar