2

Why does a class method equal itself, but isn't itself?

>>> class Test:
...     def test(self): pass
...
>>> t = Test()
>>> t.test == t.test
True
>>> t.test is t.test
False
  • http://stackoverflow.com/questions/13650293/understanding-pythons-is-operator – Marc B Jun 16 '16 at 18:41
  • Try `print(id(t.test))` on both sides of the check and you'll see why `is` isn't working – OneCricketeer Jun 16 '16 at 18:48
  • 1
    Interestingly, `print(id(t.test) == id(t.test))` prints `True` on my machine, so that might lead one to suspect that `is` would evaluate to True as well. – Kevin Jun 16 '16 at 18:50

0 Answers0