Why Test2 returns 'Yes' , but Test4 does not? | Sololearn: Learn to code for FREE!

+2

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

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

py

9/26/2019 10:13:43 AM

UraL

3 Answers

New Answer

+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/python/ref_keyword_is.asp)

+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)

+2

Thanx 2 all