@classmethod @staticmethod use

class A(object):
    a = 'a'
    @staticmethod
    def foo1(cls,name):
        print('hello', name)
        print(A.a) # 正常
        print(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')

Export

hello jc
a
come on jc
None

hello sss
a
come on sss

Guess you like

Origin www.cnblogs.com/rener0424/p/11272417.html