class Student(object): cnts = 0 def init(self, name): self.name = name Student.cnts += 1
p1 = Student('Bob') p2 = Student('Alice') print(Student.cnts)
cnts是类变量吗,可以这么定义么
Sign in to make a reply
大亮im
class Student(object): cnts = 0 def init(self, name): self.name = name Student.cnts += 1
p1 = Student('Bob') p2 = Student('Alice') print(Student.cnts)