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.

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.

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

    def add_item(self, item):

class SortedInventory(Inventory): 
    def __init__(self, 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
220,425 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.