The function properties of a class are bound to different objects and are different binding methods. When an object invokes a binding method, it passes the object itself as a self parameter
Sample code
classPeople:country=' China'? def __init__(self, name, sex, age): self. Name=name self. Sex=sex self. Age=Age ? defTest (self):Print(self)?? Conan= People ('Conan','male', 8) Wukong= People ('Wukong','male', 18)? Wukong.test ()#people.test (Wukong)Conan.test ()#people.test (Conan)?Print(People.test,people.test (123))Print(Wukong.test,wukong.test ())Print(Conan.test,wukong.test ())
Printing results:
# <__main__. People object at 0x10813a320># <__main__. People object at 0x10813a2e8># <function people.test at 0x1081291e0># <bound method People.test of <__main__. People object at 0x10813a320>># <bound method People.test of <__main__. People object at 0x10813a2e8>>
Python object-oriented programming binding method