Differences between is and == in Python
Code
if type(150421) is int :
print("!")
else :
print("?")
x = [1,2]
y = [1,2]
x == y
x is y
Description
When looking at Python code on GitHub, sometimes you see is
. Apart from the fact that the code reads smoothly like a sentence, there are clear differences from ==
and it’s good to use it appropriately:
==
simply compares values. It’s intuitive because it compares the appearance that is actually visible to us.is
compares the objects that pointers are pointing to. Essentially, it tells us whether the two are the same.