python3 静态方法,类方法和普通方法

class MyClass:
    @staticmethod
    def static_method():
        print('静态方法')

    @classmethod
    def class_method(cls):
        print('类方法')

    # 普通方法
    def normal_method(self):
        print('普通方法')



MyClass.static_method()
MyClass.class_method()
MyClass.normal_method(MyClass)
print("*"*20)
myObj = MyClass()
myObj.static_method()
myObj.class_method()
myObj.normal_method()

'''
# 输入如下
静态方法
类方法
普通方法
********************
静态方法
类方法
普通方法
'''

猜你喜欢

转载自blog.csdn.net/xiao_yi_xiao/article/details/121030095