Bound and unbound methods

class a:
    def fuc(self):
        print (self)
aa = a()
 print (a.fuc) #The method called directly by the class is called the unbound method 
print (aa.fuc) #The method called by the object of the class becomes the bound method 

aa.fuc() #Because aa .fuc is a binding method, that is, the self parameter has been bound in advance, and this parameter is the caller itself. There is no need to pass meals when calling. 
a.fuc(aa) #Because it is a non-binding method, you must pass parameters to self when calling. Note that in py2, the passed parameters must be objects of class a, while in py3, the passed parameters can be any value , From this point of view, in py3, methods defined in classes are basically no different from ordinary functions

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325088620&siteId=291194637