I created a dummy class with two empty methods:
class Foo:
def bar(self):
pass
def baz(self):
pass
When I create an instance foo
of my Foo
class, why is id(foo.bar) == id(foo.baz)
True even though the ids are obviously different?
>>> foo = Foo()
>>> id(foo.bar)
31344648
>>> id(foo.baz)
35951432
>>> id(foo.bar) == id(foo.baz)
True
However, using a function like this:
def is2(obj1, obj2):
return id(obj1) == id(obj2)
The two methods' ids are no longer equal:
>>> foo = Foo()
>>> is2(foo.bar, foo.baz)
False