-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path097_Program_Constructor Method-1.py
More file actions
30 lines (19 loc) · 1016 Bytes
/
097_Program_Constructor Method-1.py
File metadata and controls
30 lines (19 loc) · 1016 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
# Constructor Method:
# Using this method the 'value' of an object can directly be input
# It reduces the necessity of calling the input function (here, constructor method)
class student_details :
roll = ''
gpa = ''
standing = ''
def __init__ (self, roll, gpa, standing) : # Constructor method ( __init__ function )
self.roll = roll
self.gpa = gpa
self.standing = standing
# Output method
def output_value(self) :
print (f'Roll : {self.roll}, Gpa : {self.gpa}, Standing : {self.standing}')
rahim = student_details (1001, 3.65, '2nd') # input value directly into the object name
rahim.output_value() # calling the output method
# notice that the 'constructor method' has not been called
himadri = student_details (2001, 3.82, '1st')
himadri.output_value()