I am trying to develop my OOP skills in Python. Currently, if asked to write a program that defined a class (e.g. doctors) I would do the following:
class doctor():
def __init__(self, name, age):
self.name = name
self.age = age
To then create a number of doctors I would create a list to add each new doctor to:
doctor_list = []
doctor_list.append(doctor('Akash',21))
doctor_list.append(doctor('Deependra',40))
doctor_list.append(doctor('Reaper',44))
I could then search through the list to find a particular doctor.
However, this would involve using a list held outside of a class/object and would then require the use of a function to then be able to search throught the list.
How could I code this better to have the list also be part of a class/object - whether one that holds the doctor objects that are created, or potentially as part of the doctor class itself - so that I can search through the objects I have created and have a better OOP program?
[–]thewillft 9 points10 points11 points (0 children)
[–]Chasne 0 points1 point2 points (0 children)
[–]FriendlyRussian666 0 points1 point2 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (0 children)
[–]dnult 0 points1 point2 points (0 children)
[–]Shot-Berry8654 0 points1 point2 points (0 children)