class Student(object):
count = 0
def __init__(self, name):
self.name = name
Student.count += 1
为什么不能写成 self.count+=1 呢?
写成self.count += 1的话,每创建一个实例对象,类属性count会被重置为0
Sign in to make a reply
YOUTH
class Student(object):
count = 0
def __init__(self, name):
self.name = name
Student.count += 1