[1, 2, 3]? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[1, 2, 3]?

a=[1,2,3] b=[1,2,3] print(a is b) Solution: False Why is it false? 123 is the sams as 123? Is it converted from a list to a string? Any help is appreciated.

27th Mar 2019, 2:27 AM
tristach605
tristach605 - avatar
3 Answers
+ 5
The is keyword in Python checks to see if two variables are the same object and will return true if they do. This, however, means that it will return false if you compare 2 different objects even if they have the same value. In your code, although the variables a and b have the same value, they are not by any means the same object, which is why it is returning false.
27th Mar 2019, 3:16 AM
Faisal
Faisal - avatar
+ 1
Thanks for your clear answer Faisal:)
27th Mar 2019, 3:30 AM
tristach605
tristach605 - avatar
0
Thank you TT!
27th Mar 2019, 9:59 AM
tristach605
tristach605 - avatar