Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Advanced Objects Subclassing Built-ins

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

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

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:

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