python 对象方法,实例方法,静态方法

class T:
    @classmethod
    def show_class(cls):
        print('class method')

    def show_obj(self):
        print('obj')

    @staticmethod
    def show_static():
        print('static')


#对象可以调用类方法,实例方法和静态方法,这里说的调用,指的是都不用传递参数,
# python会自动传递参数过去

t =T()
t.show_class()
t.show_obj()
t.show_static()

#类可以调用类方法和静态方法
T.show_class()
T.show_static()
#类如果调用实例方法,则必须手动传入对象
T.show_obj(t)

 

你可能感兴趣的:(python)