-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9-student.py
executable file
·38 lines (31 loc) · 1.11 KB
/
9-student.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
#!/usr/bin/python3
"""
Module defines Student class, which includes method for converting
its attributes to a dictionary representation.
"""
class Student:
"""
A class to represent a student.
Attributes:
first_name (str): The first name of the student.
last_name (str): The last name of the student.
age (int): The age of the student.
"""
def __init__(self, first_name, last_name, age):
"""
The constructor for Student class.
Args:
first_name (str): The first name of the student.
last_name (str): The last name of the student.
age (int): The age of the student.
"""
self.first_name = first_name # Assign the first name
self.last_name = last_name # Assign the last name
self.age = age # Assign the age
def to_json(self):
"""
Converts the Student instance into a dictionary.
Returns:
dict: A dictionary representation of the Student instance.
"""
return self.__dict__ # Return the dictionary of the class attributes