-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-student.py
executable file
·40 lines (34 loc) · 1 KB
/
10-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
39
40
#!/usr/bin/python3
"""
10-student module
Initiates Student class that defines a student
"""
class Student():
"""Student class
"""
def __init__(self, first_name, last_name, age):
"""Initialize instance attributes
Arguments:
first_name -- Student's first name
last_name -- Student's Last name
age -- Student's age
"""
self.first_name = first_name
self.last_name = last_name
self.age = age
def to_json(self, attrs=None):
"""convert the object to json object
Returns:
The JSON object
"""
attributes = {}
if type(attrs) is list:
for attr in attrs:
if type(attr) is not str:
return self.__dict__
for key in attrs:
if self.__dict__.get(key) is not None:
attributes.setdefault(key, self.__dict__.get(key))
else:
return self.__dict__
return attributes