Question about inheritance / .super()

Hi, so I’m on exercise 9 of Inheritance / Polymorphism ( )

The code below is provided as the solution but I’m a little confused on the ‘why’. Specifically why does using append require the use of super() and sort does not since the sort method is still coming from the list parent class? Is it because in this case it’s sorting itself so the super() is assumed?

Similarly the fact that we don’t specify what list is being appended to in super().append(value) seems strange to me. I’m assuming there’s just something basic here that I’m not getting so any clarity would be appreciated.


class SortedList(list):
def append(self, value):

Second question first: super() is said to create a proxy object. That means that it says: “let’s take this object self up to the parent class and run the named method [in this case, append] found there, then bring it back here.” So self (the list) is there, inside of super().

As to your first question, super().sort() would also work as the final line.

1 Like

Ah, ok, got it - thanks!