Python之面向对象学习3


def setname(name):
def wrapper(cls):
cls.NAME = name
return cls
return wrapper

@setname('MY CLASS')
class MyClass:
pass

print(MyClass.__dict__)

class MyClass:

xxx = "XXX"

def foo(self):
print("foo")

@classmethod
def clsmd(cls):
print("{}.xxx={}".format(cls.__name__,cls.xxx))



a =MyClass()
a.foo()

MyClass.clsmd()
a.clsmd()
上一篇:【泛型】五、通配符


下一篇:Docker 系统性入门+进阶实践(2021最新版)