I understand that the is
operator is used to check whether one object points to the same memory address as another. Consider this following example:
>>> x = 5
>>> y = 10
>>> x is x
True
>>> x is y
False
>>> id(x)
499843696
>>> id(y)
499843856
Fair enough. But then I tried this comparison:
>>> x is x is x
True
I'm not sure why that evaluates to True
. It's obviously dissimilar to this:
>>> (x is x) is x
False
Because (x is x)
returns True
and (True) is x
when x
is 5 will return False
. So what is happening in the x is x is x
line? For comparison's sake:
>>> x is x is y
False
Is this syntax basically checking whether each object compared points to the memory address? I'm curious as to how that syntax is evaluated across the line.