calss Anmial(object):
count = 0
def_init_(self,name,age):
self.name = name
self.age = age
Animal.count += 1
dog = Animal('wangwang',1)
print(Animal.count)
cat = Animal('mimi',3)
print(Animal.count)
pig = Animal('panpan',1)
print(Animal.count)
Animal.count += 1 改成 Animal.count =Animal.count + 1
init的前后是两个_ ,不是一个_
class Anmial(object):
count = 0
def __init__(self,name,age):
self.name=name
self.age=age
Anmial.count+=1
dog = Anmial('wangwang',1)
print(Anmial.count)
cat = Anmial('mimi',3)
print(Anmial.count)
pig = Anmial('panpan',1)
print(Anmial.count)
class打错了 Anmial 打成Animal 能运行就怪了