So I’m doing the exercises of this link: https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-classes/lessons/inheritance-and-polymorphism/exercises/review-concepts
I got number 1 and number 2.
In exercise 3 i first tried:
But then, I was corrected with:
I understand that super is going to the parent class
List and calling it’s
append method on my
But I tried
self.append(value) because I thought that since
SortedList is a child of
List, and since I didn’t rewrite any constructors or anything, it would also inherit the
append method. But my code didn’t work, so I guess I was wrong.
So, in the next exercise (number 4) I typed:
But now, it tells me that this is also wrong, and that I should have typed:
Why do I have to use
super() in 3, but can’t use it in 4?
And why can’t I use
self in 3, but can in 4?
It’s probably something really simple, but right now I’m not seeing it.
Isn’t this a bit inconsistent?
Oh wait! Is it because of recursion?
Maybe by trying
self.append(value) in the definition of the
append method, I’m calling the method over and over again?
So maybe both
super() both work, and I just can’t use
self.method in the definition of
method… Is that it?