Python类的实例化时,类名后不加括号是什么意思
茗少顷
2023-03-10 22:45:21
共 1 个回答
公悦
2023-03-15 20:54:05
class 除了实例方法以外,还有类方法,静态方法,如下:
class Demo:
_cls_val = "cls_val"
def __init__(self):
_inst = "inst"
def inst(self):
return self._inst
@classmethod
def clsmethod(cls):
return cls._cla_val
@staticmethod
def staticmethod():
return "static"调用的时候也会不一样
阅读原文