要将三个类方法写到类里面。参考https://blog.csdn.net/polyhedronx/article/details/81911548
class Root:
__total=0
def __init__(self,v):
self.__value=v
Root.__total+=1
def show(self):
print('self.__value:',self.__value)
print('Root.__total:',Root.__total)
@classmethod
def classShowTotal(cls):
print(cls.__total)
@staticmethod
def staticShowTotal():
print(Root.__total)
r=Root(3)
r.classShowTotal()
r.staticShowTotal()
rr=Root(5)
Root.classShowTotal()
定义的那个方法有参数,你调用的时候没传参。。。