-
Notifications
You must be signed in to change notification settings - Fork 0
/
constructors.py
50 lines (34 loc) · 983 Bytes
/
constructors.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
# python code for default constructor
class SkycrewFamily:
# defualt constructor
def __init__(self):
self.sky = 'Skycrew'
# method for printing the data members
def print_sky(self):
print(self.sky)
# creating object of the class
obj = SkycrewFamily()
# calling the instance method using the object
# obj.print_sky()
# parameterized constructor
class Addition:
first = 0
second = 0
answer = 0
# parameterized constructor
def __init__(self, f, s):
self.first = f
self.second = s
def display(self):
print(f'Firts number = {self.first}')
print(f'Second number = {self.first}')
print(f'Addition of two number = {self.answer}')
def calculate(self):
self.answer = self.first + self.second
# creating object of the class
# this will invoke parameterized constructor
obj = Addition(1000, 2000)
# perform Addition
obj.calculate()
# display result
obj.display()