-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_oops_6.py
More file actions
33 lines (24 loc) · 799 Bytes
/
Python_oops_6.py
File metadata and controls
33 lines (24 loc) · 799 Bytes
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
# Static Method
class Employee:
no_of_leaves =8
def __init__(self, name, salary, role):
self.name = name
self.salary = salary
self.role = role
def print_details(self):
return f"Name is (self.name), Salary is (self.salary) and Role is (self.role)"
@classmethod
def change_leaves(cls, new_leaves):
cls.no_of_leaves = new_leaves
@classmethod
def from_string(cls, string):
params = string.split("-")
return cls(params[0], params[1], params[2])
#shortcut
# cls(*string.split("-"))
@staticmethod
def printgood(string):
print(f"Nikhil is a good " + string)
nikhil = Employee('Nikhil', 30000, 'Student')
tarun = Employee.from_string("Tarun-70000-Teacher")
Employee.printgood("boy")