Challenge question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Challenge question

a,b=[0],[0] a,b=b,a print(a,b) if (a is b): print ("True") else: print("False") why is it False? I checked the values of a and b,both are[0]

16th Aug 2019, 4:45 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
4 Answers
+ 15
Imagine that both you and your friend bought the same sneakers (x = [sneakers], y = [sneakers]). They are equal to each other (x == y) in both style and price. But these are different sneakers (x is not y)
16th Aug 2019, 5:15 AM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 8
Almost always, but say 1 is always 1, or 'str' is always 'str' x=1 y=1 print(x is y) >>>True
16th Aug 2019, 6:50 AM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 1
Михаил Горчанюк does that mean whenever I input a,b=b,a a is always not b?
16th Aug 2019, 5:33 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
+ 1
OK, thank you very much
16th Aug 2019, 6:51 AM
Hoh Shen Yien
Hoh Shen Yien - avatar