Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Inheritance Super!

Overriding methods using super()

The whole concept of using the super() to use a method from a parent class is entirely confusing and now I tried overriding the add_item method but the code won't work. What really is the purpose of super() and how is it used? I have repeated the tutorial like the 6th time now but I'm failing to get the sense around it all and also how to use it. Please help. A detailed explanation can be handy too because I literally have 0 idea of what I am doing. Thanks in advance.

inventory.py
class Inventory:
    def __init__(self):
        self.slots = []

    def add_item(self, item):
        self.slots.append(item)

class SortedInventory(Inventory): 
    def __init__(self, add_item):
        super().add_item()
Daniel Adari
Daniel Adari
3,577 Points

Hi! Here's a detailed explanation about the super() method.

If you need any more help regarding this specific challenge just reply to this message.

Good luck!

1 Answer

Steven Parker
Steven Parker
229,644 Points

Using "super" allows you to call a method in the parent class that has the same name as one in your derived class.

The main issue here is that this code is overriding "__init__" , but the instructions ask you to create an override for "add_item" instead. You won't need to override "__init__" in this challenge.