+ 2

Why b not change its value?

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

22nd Jun 2020, 8:33 AM
Nig
2 Respostas
+ 2
b will not charge because both a and b are references to different values.If you get confused try to print the id of a and b print(id(a)) print(id(b))
22nd Jun 2020, 8:58 AM
uday kiran
uday kiran - avatar
0
Why it will change You assigned b =a[:] Which means b contain the value from beginning to end and if you want to change value then change value before passing value to b
22nd Jun 2020, 8:56 AM
Ayush Kumar
Ayush Kumar - avatar