-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10-student.py
More file actions
28 lines (25 loc) · 758 Bytes
/
10-student.py
File metadata and controls
28 lines (25 loc) · 758 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
#!/usr/bin/python3
"""
Class Student
Public instance attributes:
- first_name
- last_name
- age
"""
class Student():
def __init__(self, first_name, last_name, age):
""" Constructor """
self.first_name = first_name
self.last_name = last_name
self.age = age
def to_json(self, attrs=None):
""" retrieves a dictionary representation of a Student instance
check if attrs is a list, if not retrieve None
"""
if isinstance(attrs, list):
for item in attrs:
if not isinstance(item, str):
return self.__dict__
return {key: self.__dict__[key]
for key in attrs if key in self.__dict__}
return self.__dict__