Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class student:
- total_students = 0
- def __init__(self, name):
- self.name = name
- student.total_students = student.total_students + 1
- @classmethod
- def get_total_students(cls):
- return cls.total_students
- student1 = student("Alice")
- student2 = student("Bob")
- student2 = student("naren")
- total_students = student.get_total_students()
- print("Total students:", total_students)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement