Riju21

35_classmethod_staticmethod

May 12th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. class Employe:
  2.     no_of_emp = 0
  3.     raise_amount = 2.5
  4.     def __init__(self, fname, lname, pay):
  5.         self.first = fname
  6.         self.last = lname
  7.         self.pay = pay
  8.        
  9.         Employe.no_of_emp += 1
  10.    
  11.     def name(self):
  12.         self.mail = self.first + '@gmail.com'
  13.         # return ('{} {}'.format(self.first, self.last))
  14.         return ('{}'.format(self.mail))
  15.  
  16.  
  17.     def apply(self):
  18.         self.pay = self.pay * self.raise_amount
  19.  
  20.     @classmethod                        # is used to set value through obj
  21.     def chng_raise_amnt(cls, amount):
  22.         cls.raise_amount = amount
  23.            
  24.     @classmethod
  25.     def form_str(cls, emp_str):
  26.         fn, ln, amn = emp_str.split('-')
  27.         return cls(fn,ln,amn)
  28.  
  29.  
  30.  
  31. emp_1 = Employe('riju', 'chowdhury', '3000')
  32. # emp_1.apply()
  33. # emp_1.pay
  34.  
  35. emp_str_1 = 'samrat-mitra-6000'
  36. new_emp_1 = Employe.form_str(emp_str_1)
  37.  
  38. print(new_emp_1.name())
  39.  
  40. # emp_1.chng_raise_amnt(3.09)
  41.  
  42. # print(Employe.raise_amount)
  43. # print(emp_1.raise_amount)
  44. # print(emp_1.raise_amount)
Advertisement
Add Comment
Please, Sign In to add comment