Advertisement
naren_paste

Class methods

Jan 18th, 2024
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | Source Code | 0 0
  1. class Student1:
  2.     def __init__(self, name, email):
  3.         self.name = name
  4.         self.email = email
  5.  
  6.     @classmethod
  7.     def stu_details(cls, name, email):
  8.         return cls(name, email)
  9.  
  10.     @classmethod
  11.     def details(cls, student_instance):
  12.         print(student_instance.name, student_instance.email)
  13.  
  14.     def student_details(self):
  15.         print(self.name, self.email)
  16.  
  17.     def result(self):
  18.         print(self.name, "is passed")
  19.  
  20. # Creating an instance using classmethod
  21. su = Student1.stu_details("ram", "ram@gmail.com")
  22.  
  23. # Calling instance method student_details
  24. su.student_details()
  25.  
  26. # Calling class method details
  27. Student1.details(su)
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement