I have a fun little exercise for you.
I want you to create a super list using the class super list.
Now in here, I want you to add code that allows us to have just like we have a list in Python allow
us to access through index through well any way that a regular list allows us to use it.
But the only difference is that the super list is going to have a special dunder method.
Let's say that when we do length.
So when we define Dunder Dunder length, we're going to modify it and we're going to have it return
no matter what.
1000.
Now this may look easy because all we want to do is modify the length dunder here.
But the question is, based on what you learned about inheritance, about object oriented programming,
instead of having to write every single dunder that we need to use on a list, how can we easily acquire
the power that list already has and then just modify this length?
Dunder So remember, super list is going to be a list that we can create.
We can instantiate like this super list, one we're going to call.
Super list.
And it's going to allow us to do things like length, super list.
And also access items in the super list or use super list.
One dot, let's say a pen.
And maybe a pant five and actually get super.
Lest one.
All right, take it away from here.
Give it a go.
Pause the video, because I'll give you the answer.
So let's just implement this.
We're going to have self in here and we're only going to return, let's say, 1000.
So that when we call super list one and let's comment this out.
And I do lengthier.
Let's print it out.
I should get 1000.
That's good.
But I want the functionality of this.
I want to be able to append to my super list.
So let's run this and see what happens.
I get an attribute error super list object has no attribute append.
Hmm.
Let's think about this.
How can we acquire the powers that lists in Python already have?
What we learned about inheritance.
Right.
And all we have to do is just simply type list here and now.
List becomes our parent class of superclass.
So let's give this a go.
Now, if I click Run.
All right, that seems to work.
What if we want to access super list at index?
Well, not five at index of zero.
If I click run.
I get 1000.
Well, that's because we're not printing anything yet, so let's print here.
And Click Run.
Check that out.
We're able to have this super list and we just extended the functionality of list.
How cool is that?
Now to double check.
There's a fun little function that we have in Python and it's called is sub class.
And here we say super list.
And List if I click Run.
I get true because is super list a subclass of list?
Yep, that's true.
What about this is list a subclass of the base object?
Yep.
It's true.
Remember, everything in Python is an object that inherits from the base object class.
We then inherit some built in list methods and we're able to use all of that in our super list just
by inheriting like this.
Very, very cool.
Now for some of you, this might have been a simple exercise and you got it right away if you didn't.
Don't worry.
Now, you know, pretty cool.
I'll see you in the next one.
Bye bye.