示例代码
class People: country = ‘China‘ ? def __init__(self, name, sex, age): self.Name = name self.Sex = sex self.Age = age ? def test(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())
打印结果:
# <__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>>