Advertisement
193030

Python class variables

Jan 5th, 2022
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. class Employee:
  2.     raise_amount = 1.05
  3.     num_of_empl = 0
  4.     def __init__(self,first,last,pay):
  5.         self.first = first
  6.         self.last = last
  7.         self.pay = pay
  8.         self.email = first + '.' + last + '@company.com'
  9.         Employee.num_of_empl +=1
  10.  
  11.     def fullname(self):
  12.         return '{} {}'.format(self.first, self.last)
  13.  
  14.     def apply_raise(self):
  15.         self.pay = int(self.pay * self.raise_amount)
  16.  
  17.  
  18. emp_1 = Employee('Corey','Shafer', 50000)
  19. emp_2 = Employee('Vanila','Parker', 40000)
  20.  
  21.  
  22. print(emp_1.__dict__)
  23. print(emp_1.raise_amount)
  24. print(emp_1.pay)
  25. # emp_1.pay *= 1.01
  26. emp_1.apply_raise()
  27. emp_1.raise_amount = 1.06
  28.  
  29. emp_1.apply_raise()
  30. print(emp_1.pay)
  31.  
  32. print(emp_1.num_of_empl)
  33.  
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement