On 2/8/2012 10:48 PM, Emeka wrote:

class Boo(object):

     def __init__(self , moon, sun):
         self.moon = moon
self.sun = sun
     def daf(self):
         return self.sun + self.moon
     def ball(self):
         return self.sun * self.moon


print Boo.__dict__

{'__module__': '__main__', 'ball': <function ball at 0x286e9b0>, 'daf':
<function daf at 0x286e938>, '__dict__ ......}

print  hex(id(Boo.daf))
0x27de5a0

My question is why is it that the id of Boo.daf  is different from daf's
hex value in the above dict?

Because you are using Python 2. Just print Boo.daf and you will see that it is not a 'function'. In Python 3, it will be, and have the same address.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to