Advertisement
naren_paste

class_students

Mar 22nd, 2024
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | Source Code | 0 0
  1. class student:
  2.     total_students = 0
  3.  
  4.     def __init__(self, name):
  5.         self.name = name
  6.         student.total_students = student.total_students + 1
  7.  
  8.     @classmethod
  9.     def get_total_students(cls):
  10.         return cls.total_students
  11.  
  12. student1 = student("Alice")
  13. student2 = student("Bob")
  14. student2 = student("naren")
  15.  
  16. total_students = student.get_total_students()
  17. print("Total students:", total_students)  
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement