面向对象类成员之类方法

# 类方法,属于类,通过类来调用。

# 自动传参cls

class Provice:
    # 静态字段,类中
    country = "China"

    def __init__(self, name):
        temp = "xxx"
        # 普通字段,对象中(self就是对象)
        self.name = name

    # 普通方法,类中
    def show(self):
        print("show")

    # 静态方法,()中没有self;但是可以传值
    # 静态方法属于类,通过类调用。
    @staticmethod
    def xo(bk):
        print("xo")
        print(bk)

    # 类方法
    @classmethod
    def xxoo(cls):
        print("xxoo",cls)

# 通过类来调用。
Provice.xxoo()

猜你喜欢

转载自www.cnblogs.com/xuwenwei/p/9784335.html