Why Test2 returns 'Yes' , but Test4 does not? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why Test2 returns 'Yes' , but Test4 does not?

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

26th Sep 2019, 10:13 AM
UraL
3 Answers
+ 3
"The is keyword is used to test if two variables refer to the same object. The test returns True if the two objects are the same object. The test returns False if they are not the same object, even if the two objects are 100% equal. Use the == operator to test if two variables are equal.“ (https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_keyword_is.asp)
26th Sep 2019, 10:28 AM
Michael
Michael - avatar
+ 3
Yes4 was not printed because L is not [1], they are 2 separate objects. Yes2 was printed, because integers, and many other primitive datatypes have different behavior. You could say, that 6 is always 6 and 308 is always 308, but [1, 7] is not always [1, 7], because it's values can be changed. a is b equals id(a) == id(b)
26th Sep 2019, 10:35 AM
Seb TheS
Seb TheS - avatar
+ 2
Thanx 2 all
26th Sep 2019, 11:15 AM
UraL