forked from growdataskills/Python_Fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassmethod.py
More file actions
34 lines (24 loc) · 678 Bytes
/
Copy pathclassmethod.py
File metadata and controls
34 lines (24 loc) · 678 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
33
34
#method 1:-
class employee():
def __init__(self,salary):
self.salary = salary
@classmethod
def changeSalary(cls,sal):
return cls(sal)
def income(self):
print(self.salary)
e = employee(100)
e.income()
# e1 = e.changeSalary(500)
e1 = employee.changeSalary(500)
e1.income()
# -------------------------------------------------------------------------------------------------------------------------------------------------------------
#method 2:-
# class employee():
# salary = 100
# def changeSalary(self,sal):
# self.__class__.salary = sal
# e = employee()
# print(e.salary)
# e.changeSalary(500)
# print(e.salary)