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 trialAli Dahud
3,459 PointsQuestion 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
Treehouse Moderator 68,457 PointsSince 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
39,021 PointsHi 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
-Greg
Chris Freeman
Treehouse Moderator 68,457 PointsWhile 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.
Ali Dahud
3,459 PointsAli Dahud
3,459 PointsChris Freeman Jennifer Nordell Greg Kaleka Sean T. Unwin Vittorio Somaschini would you be so kind and please reply?