The Python is
operator is used to test if two variables refer to the same object.
>>> x = [1, 2]
>>> x = y
>>> x is y
True
>>> x = [1, 2]
>>> y = [1, 2]
>>> x is y
False
It’s not the same as the ==
operator, which tests if the values are equal. With is
it doesn’t matter if the values are equal, it has to actually refer to the same object.
Note that constants refer to the same object in Python
>>> x = 3
>>> y = 3
>>> x is y
True