I wanted to know whether an object has a copy of all its class methods. So I created a class person
, defined a method getName
and created an object Harry
. I used dir
function to check whether both the class and the object have getName
method stored inside them and both of them returned true. I then printed out the getName
method of both the class and the object and they returned different addresses, but I noticed that harry.getName
method is bounded to person.getName
. So does that mean that harry.getName
is not a copy of its class method rather just a reference to its class method. To check this used delattr
method to delete the getName
attribute of the person class and again used dir
to check it. And as expected it deleted it from both the class person
and object Harry
.
So please review my code and tell whether my thoughts are correct.
Note:
The dir()
function returns all properties and methods of the specified object, without the values.
The delattr()
method is used to delete the named attribute from the object, with the prior permission of the object.