-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2_Constructor.py
52 lines (47 loc) · 1.26 KB
/
2_Constructor.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
#C0d3 n0=2
#made By GuND0Wn151
"""
Class with a one parameter constructor
initialized with one parameter whihc is a string called name
"""
class Employer1:
salary=10000
def __init__(self,name):
print("In The Employer1 Constructor");
self.name=name
def Salary(self, parameter_list):
"""
docstring
"""
print(salary)
def Display(self):
print("Employer1 Details")
print("Name: ",self.name)
print("Salary: ",self.salary)
"""
Class with a zero parameter constructor
initialized (just created object)
creating a method or fucntion whihc assigns the variables
"""
class Employer2:
def __init__(self):
print("In The Employer2 Constructor")
def salary(self,a):
self.salary=a
def name(self,a):
self.name=a
def Display(self):
print("Employer2 Details")
print("Name: ",self.name)
print("Salary: ",self.salary)
"""
when ever object is created the __init__ method
asscioated with the class is called and object is created
"""
test1=Employer1("Ram")
test2=Employer2()
test1.Display()
print("-----------------------")
test2.name("Rick")
test2.salary(100)
test2.Display()