All the id()
in the following python program prints the same value. I had thought different member functions are different objects therefore id()
should return different values. Why does id()
return the same values?
class A():
def x(self):
print 'x'
def __y(self):
print 'y'
def y(self):
self.__y()
class B(A):
def x(self):
self.jj = 20
print 'bx'
def __y(self):
self.sj = 20
print 'by'
print 'by'
ta = A()
tb = B()
ta.x()
ta.y()
ta._A__y()
tb.x()
tb._A__y()
tb._B__y()
tb.y()
print id(ta.x)
print id(ta.y)
print id(ta._A__y)
print id(tb.x)
print id(tb._A__y)
print id(tb._B__y)
print id(tb.y)
The next question (actually that was the original question I had) would be, how to examine if tb._A__y and tb.y really invokes the same function. I had though using id() will tell me the answer if id() returns the address of a function. But now I udnerstand it doesn't work that way in Python.