-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.2.py
More file actions
34 lines (27 loc) · 767 Bytes
/
Copy path3.2.py
File metadata and controls
34 lines (27 loc) · 767 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
# write a program to demonstrate the constructors
#constructors
class ComplexNumber:
def __init__(self,r=0,i=0):
self.real= r
self.imag= i
def getData(self):
print("{0}+{1}j".format(self.real,self.imag))
c1 = ComplexNumber(5,6)
print(c1.getData())
#Python non-parameterized constructor
class Student:
def __init__(self):
print("This is non-parametrized Constructors")
def show(self,name):
print("Hello",name)
student = Student()
student.show("Milan")
#parametrized Constructors
class Student:
def __init__(self,name):
print("This is the parametrized Constructors")
self.name = name
def show(self):
print("Hello",self.name)
student = Student("Milan")
print(student.show())