>记录生活, 工作的点点滴滴...

python 创建类的实例的个数counter

class B(object):
counter=0
def __new__(cls):
cls.counter =cls.counter+1
return super(B,cls).__new__(cls)
def Counter(self):
print(self.counter)
if __name__=="__main__":
a=B()
b=B()
c=B()
c.Counter()
b.Counter()


发表于:2019-01-20 07:53:55浏览(192) 评论(0) Python