'''class Student():
add = 0
def __init__(self, name, age):
self.name = name
self.age = age
self.__class__.add += 1
print(self.__class__add)
student1 = Student('Jimmy',22)
student2 = Student('Robin',23)'''
class Student():
add = 0
def __init__(self,name,age):
self.name = name
self.age = age
self.__class__.add += 1
print(self.__class__.add)
student1 = Student('jimmy',18)
student2 = Student('robin',16)
注释掉的是报错的,对比下面可执行的没什么区别啊,就是报错
'Student' object has no attribute '_Student__class__add'