-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructor.py
More file actions
37 lines (31 loc) · 855 Bytes
/
constructor.py
File metadata and controls
37 lines (31 loc) · 855 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
35
36
37
class Student:
"""
Returns a ```Student``` object with the given name, branch and year.
"""
def __init__(self, name, branch, year):
self.name = name
self.branch = branch
self.year = year
print("A student object is created.")
def print_details(self):
"""
Prints the details of the student.
"""
print("Name:", self.name)
print("Branch:", self.branch)
print("Year:", self.year)
# It will throw error missing 3 required postional arguments
#student1 = Student()
student1 = Student("Prasad" , "CSE", 4)
student1.print_details()
student2 = Student("Harry", "Civil", 3)
student2.print_details()
#Output:
A student object is created.
Name: Prasad
Branch: CSE
Year: 4
A student object is created.
Name: Harry
Branch: Civil
Year: 3