+ 2
Why Test2 returns 'Yes' , but Test4 does not?
3 Réponses
+ 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)
+ 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