Python 总是将实例作为实例方法的第一个参数传递,这意味着有时有关参数数量的错误消息似乎会减少一个。
class testclass:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        self.test()
    def test(self):          ## instance method
        print('test', self)
if __name__ == '__main__':
    x = testclass(2,3)
如果您不需要访问类或实例,则可以使用如下所示的静态方法
class testclass:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        self.test()
    @staticmethod
    def test():
        print('test')
if __name__ == '__main__':
    x = testclass(2,3)
一个类方法是类似的,如果你需要访问class,而不是实例
class testclass:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        self.test()
    @classmethod
    def test(cls):
        print('test', cls)
if __name__ == '__main__':
    x = testclass(2,3)