# -*- coding: utf-8 -*- class Student(object): count = 0 def __init__(self, name): self.name = name Student.count += 1 # 每次调用这个方法创建实例,则Count+1 if Student.count != 0: print('测试失败,Count: %s' % Student.count) else: bart = Student('Bart') if Student.count != 1: print('测试失败,Count: %s' % Student.count) else: lisa = Student('Lisa') if Student.count != 2: print('测试失败,Count: %s' % Student.count) else: print('Stundents:', Student.count) print('测试通过')
Python 统计学生数
最新推荐文章于 2024-09-11 10:35:44 发布