class Newclass(object):
num_count=0
def init(self,name):
self.name=name
num_count+=1
print(name,Newclass.num_count)
def del(self):
Newclass.numcount-=1
print('del',self.name,num_count)
我尝试aa=Newclass(“hello”)报错如下
Exception ignored in: <function Newclass.__del__ at 0x0000000002FE6040>
Traceback (most recent call last):
File "<pyshell#59>", line 9, in del
NameError: name 'numcount' is not defined
Traceback (most recent call last):
File "<pyshell#64>", line 1, in
aa=Newclass('ni')
File "<pyshell#63>", line 5, in init
numcount+=1
UnboundLocalError: local variable 'numcount' referenced before assignment这是怎么回事