题目要求:
编写一个学生类, 要求有一个计数器的属性, 统计总共实例化了多少个学生。
class Student:
count = 0
@classmethod
def __init__(cls):
cls.count += 1
a1 = Student()
a2 = Student()
a3 = Student()
a4 = Student()
print(Student.count)
题目要求:
编写一个学生类, 要求有一个计数器的属性, 统计总共实例化了多少个学生。
class Student:
count = 0
@classmethod
def __init__(cls):
cls.count += 1
a1 = Student()
a2 = Student()
a3 = Student()
a4 = Student()
print(Student.count)