+ 1

What exactly does "is" do in python?

27th Jan 2019, 7:45 PM
Mjavady97
Mjavady97 - avatar
5 Respuestas
+ 7
"a is b" = "id(a) == id(b)"
27th Jan 2019, 9:04 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 2
https://docs.python.org/3/reference/expressions.html#identity-comparisons
27th Jan 2019, 8:02 PM
Diego
Diego - avatar
+ 1
But not necessarily True if the compared values are of the same type. a = [1, 2, 3] b = list(a) print(type(a)) # <class 'list'> print(type(b)) # <class 'list'> print(a is b) # Fasle
27th Jan 2019, 9:00 PM
Diego
Diego - avatar
0
I have discovered, that it is almost same than ==, but returns False, if compared values aren't the same type. (Like === in JavaScript) 0 == 0.0 #True 0 is 0.0 #False 0 is 0 #True
27th Jan 2019, 8:54 PM
Seb TheS
Seb TheS - avatar
0
It checks to see if the two object are the same or not. They have to be exactly the same and with no change.
4th Feb 2019, 11:35 AM
Mjavady97
Mjavady97 - avatar