@Kapil3sh/

Class methods and Static Methods

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Employee:
  raise_amt = 1.04
  num_of_employees = 0

  def __init__(self, first, last, pay):
    self.first = first
    self.last = last
    self.pay = pay
    self.email = first+"."+last+"@companyname.com"
    Employee.num_of_employees += 1

  def display_full(self):
    return '{} {}'.format(self.first,self.last)
  
  def apply_raise(self):
    self.pay = int(self.pay*self.raise_amt)
    return self.pay
  
  @classmethod
  def set_raise_amt (cls, amount):
    cls.raise_amt = amount
  
  @classmethod
  def from_string(cls, emp_string):
    first, last, pay = emp_string.split('-')
    return cls(first,last,pay)

  @staticmethod
  def is_workday(day) :
    if day.weekday() == 5 or day.weekday() == 6:
      return False
    return True


import datetime

my_date = datetime.date(2019,5,17)

print(Employee.is_workday(my_date))



print(Employee.num_of_employees)

emp1 = Employee('kapilesh','kothavale',60000)
emp2 = Employee('test','user',50000)

emp1.set_raise_amt(1.05)

print(emp1.raise_amt)
print(emp2.raise_amt)
print(Employee.raise_amt)

emp3 = Employee.from_string("John-Doe-70000")
print(emp3.email)
print(emp3.pay)
print(Employee.num_of_employees)