Discuss / Python / 1

大亮im

#1 Created at ... [Delete] [Delete and Lock User]

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是类变量吗,可以这么定义么


  • 1

Reply