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 Inheritance Multiple Superclasses

Ali Dahud
Ali Dahud
3,459 Points

Question Python-Multiple SuperClass

My question is that why didnt he use for loop where he used the

def __init__(self,*args, **kwargs):
    super()

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Since the Character class at end of the inheritance chain uses a loop on *args and *kwargs, the preceding classes in the inheritance chain, Agile and Sneaky, and the sub-class Thief, only have to pass along their unconsumed arguments using *args and **kwargs using super(). The final loop in Character.__init__() will take care of instantiating everything.

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Ali,

Kenneth never defines an init method on a class that inherits from multiple super classes. There's no need for any looping.

In fact... even if we were defining an init method on a class with multiple superclasses, there's still no need to loop.

You might find this SO question and answer helpful.

Cheers :beers:

-Greg

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

While Kennth doesn’t appear to define an __init__ method for a class that has multiple super classes within the Treehouse content, I confirmed with Kenneth that β€˜never’ is an overstatement. There may be situations where an __init__ is warranted in a class that inherits from multiple classes.