-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10-student.py
More file actions
executable file
·33 lines (25 loc) · 967 Bytes
/
10-student.py
File metadata and controls
executable file
·33 lines (25 loc) · 967 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
#!/usr/bin/python3
"""Defines a class Student."""
class Student:
"""Represent a student."""
def __init__(self, first_name, last_name, age):
"""Initialize a new Student.
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
self.last_name = last_name
self.age = age
def to_json(self, attrs=None):
"""Get a dictionary representation of the Student.
If attrs is a list of strings, represents only those attributes
included in the list.
Args:
attrs (list): (Optional) The attributes to represent.
"""
if (type(attrs) == list and
all(type(ele) == str for ele in attrs)):
return {k: getattr(self, k) for k in attrs if hasattr(self, k)}
return self.__dict__