+ 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 Respuestas
+ 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
En tendencia hoy
.
1 Votes
What?
0 Votes
HTML
0 Votes
Web
0 Votes
Quiz duel
0 Votes
FRC Coding?
1 Votes
help
0 Votes
AI
2 Votes
APIs
1 Votes