@classmethod @staticmethod 使用

class A():
    a = 'a'
    @staticmethod
    def foo1(cls,name):
        print('hello', name)
        print(A.a) # 正常
        cls().foo2(name)
    def foo2(self, name):
        print('come on', name)
    @classmethod
    def foo3(cls, name):
        print('hello', name)
        print(A.a)
        cls().foo2(name)

A.foo1(A,'jc')
A.foo3('sss')

输出

hello jc
a
come on jc
None

hello sss
a
come on sss

posted @ 2019-07-30 20:08  Rener  阅读(95)  评论(0编辑  收藏  举报