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

0

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

+5

[:] 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

+3

https://code.sololearn.com/cUVsE6fxgkG4/?ref=app

+3

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

+2

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

+1

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