The Python documentation about the is
operator says:
The operators
is
andis not
test for object identity:x is y
is true if and only ifx
andy
are the same object.x is not y
yields the inverse truth value.
Let's try that:
>>> def m():
... pass
...
>>> m is m
True
The Python documentation also says:
Due to automatic garbage-collection, free lists, and the dynamic nature of descriptors, you may notice seemingly unusual behaviour in certain uses of the
is
operator, like those involving comparisons between instance methods, or constants. Check their documentation for more info.
>>> class C:
... def m():
... pass
...
>>> C.m is C.m
False
I searched for more explanations, but I was not able to find any.
Why is C.m is C.m
false?
I am using Python 2.x. As noted in the answers below, in Python 3.x C.m is C.m
is true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With