+ 1
What exactly does "is" do in python?
5 Réponses
+ 7
"a is b" = "id(a) == id(b)"
+ 2
https://docs.python.org/3/reference/expressions.html#identity-comparisons
+ 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
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
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.