Python Object-Oriented Python Advanced Objects Subclassing Built-ins

Adrian Diaz
Adrian Diaz
2,742 Points

Why use super() if there is no parent class?

Im confused as to how super works. I thought it was used to inherit a method from a parent class. If there is no parent class how is super still useful?

2 Answers

jayda hendrickson
jayda hendrickson
2,545 Points

Remember, Super() isn't just necessarily used to inherit methods from a parent class but to override methods that the parent class has assigned. By doing that it also inherits certain methods and overrides others that it wants to change

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

Hi there, Adrian Diaz! There are parent classes. A str() is making a new instance of a string. It's easy to think of them as "primitive data types" but they are contained in what is known as "object wrappers". Ever heard that everything in Python is an object?

name = "Adrian"
print(name.upper())  # I am calling the upper method on the instance of string

The .lower() and .upper() are methods on instances of string. Just like append() and sort() are methods on an instance of a list.

In the example code we see:

class FilledList(list):

That means it is inheriting from list. So it has methods like sort() and append just like any normal list because it got it from its parent...list :smiley:

Hope this helps! :sparkles: