类方法&实例方法&静态方法

class S():
    def __init__(self, a):
        self.a = a

    def x(self):
        print('a is', self.a)

    @classmethod
    def b(*args):
        print('arg is', args)

    @classmethod
    def c(cls):
        print('cls is', cls)

    @staticmethod
    def d(*args):
        print('arg is', args)


s = S(10)
s.x()
s.b()
s.d()
s.c()

# a is 10
# arg is (<class '__main__.S'>,)
# arg is ()
# cls is <class '__main__.S'>
posted @ 2020-09-01 21:34  嗨,阿良  阅读(224)  评论(0编辑  收藏  举报