why is the answer false false ? | Sololearn: Learn to code for FREE!


why is the answer false false ?

a = [1,[2,3]] b= [1,2,3] c=a[:] d = b[:] print(c is a , d is b )

10/15/2020 2:09:58 PM

Curious Ant

5 Answers

New Answer


[:] makes a copy of a list. The new list will be equal - like a twin. But it's not the original same list. Therefore 'is' gives False. If you write c==a, you get True. For more details, read this: https://code.sololearn.com/c89ejW97QsTN/?ref=app




Slick, the fun begins when you add this line to your code: print(a[1] is b[1])


HonFu i wonder why that is, they also have the same id! The madness


Slick, you will find the reason in my tutorial. 😉