Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Arjun Amin
2,228 PointsI have no idea what to do
I have been asked:
'Great! Now override the add_item method. Use super() in it to make sure the item still gets added to the list.'
Please assist me through the whole process because I don't understand the question.
Thanks.
class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
pass
5 Answers

Christopher Shaw
Python Web Development Techdegree Graduate 58,236 PointsSuper allows you to call a function from the parent class. So effectively we are calling (running) the add_item function in the parent class. And sending it the item.
def add_item(self, item):
super().add_item(item)

GLEB CHEMBORISOV
11,182 PointsTry this: class SortedInventory(Inventory):
def __init__(self, slots=[]):
super().__init__()
self.slots=slots
def add_item(self,item):
self.slots.append(item)

Qiong Li
4,192 Pointsclass SortedInventory(Inventory): def add_item(self, item): super(SortedInventory,self).add_item(item)

Denis Watida Machaka
7,311 Pointsclass SortedInventory(Inventory): def add_item(self,item): super().add_item(item)

Derek Hawkins
12,783 PointsI would have to agree with everyone else. This example is extremely contrived and makes no sense to do. But this worked:
class Inventory: def init(self): self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory): def add_item(self, item): super().add_item(item)
nicole lumpkin
Courses Plus Student 5,328 Pointsnicole lumpkin
Courses Plus Student 5,328 PointsThanks Christopher, I too was confused by this!
nicole lumpkin
Courses Plus Student 5,328 Pointsnicole lumpkin
Courses Plus Student 5,328 PointsI guess at this point I don't understand why I wouldn't include self like this:
Keith Ostertag
16,619 PointsKeith Ostertag
16,619 PointsHmm... I'm still not getting this. Since we've already made SortedInventory a subclass of Inventory, then why do we need to use super to call the add_item method? Isn't the whole point of making it a subclass to pass all the methods down from the parent?
At least at this point we haven't changed that method, correct? So is this just the first step in altering the add_item method for the SortedInventory class? Meaning, if we weren't planning to change this method we wouldn't be defining add_item in the SortedInventory class?