类方法、静态方法

class B:
    country = 'China'  # 静态变量(属性,字段)

    def func(self):  # 动态普通方法
        pass

    def __init__(self,name,age):  # 特殊方法:双下方法
        self.name = name


    @classmethod  # 类方法
    def func2(cls):
        # print(cls)
        cls.area = '东北'
        cls.name = '狗哥'
print(B)
print(B.__dict__)
B.func2()
print(B.__dict__)

猜你喜欢

转载自www.cnblogs.com/wangkaiok/p/9988051.html