1. 程式人生 > >python 計算建立類的例項的個數

python 計算建立類的例項的個數

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