The Python documentation about the is operator says:
The operators
isandis nottest for object identity:x is yis true if and only ifxandyare the same object.x is not yyields 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
isoperator, 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