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

super help

I thought super could only be used when we had a parent class? also, dict seems to be an argument for the class, and i thought the names of parent classes went into the parenthesis of a class.

Ryan Cross
Ryan Cross
5,742 Points

I thought super could only be used when we had a parent class?

true! but object is the mother of all classes....everything is descended from object

not exactly , there is something called MRO read this: https://makina-corpus.com/blog/metier/2014/python-tutorial-understanding-python-mro-class-search-path this is how python is looking for super, and by understanding the MRO you will understand super better see the examples and try them yourself, also add prints everywhere

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

I thought super could only be used when we had a parent class?

The default parent included in all classes is the object class. It can be seen by examining the class Method Object Resolution attribute

$ python
Python 3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class NoParent:
...     pass
... 
>>> np = NoParent()
>>> np.__class__.__mro__
(<class '__main__.NoParent'>, <class 'object'>)

Also, dict seems to be an argument for the class, and i thought the names of parent classes went into the parenthesis of a class.

In this case, dict is the parent class and not an argument. The built-in types, such as dict could have been capitalized as other class names but the built-in types were left lower cased.