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 Super-Duper!

Arcee Palabrica
Arcee Palabrica
8,100 Points

Need more explanation on setting super before setting self.sneaky

Hi guys I'm a little bit confused at the super and self.sneaky part.

At 1:54 Kenneth Love mentioned that setting self.sneaky before super could override what we want to set.. I kinda got lost in that part.. can anyone explain further what it means? (1) why we set super first then self.sneaky and (2)why don't we just set sneaky in the kwargs when we initialize Thief?

David Bath
David Bath
25,940 Points

I think what he was saying is that the value of sneaky could be overridden by a value passed into **kwargs when the super class gets called. Let's say you always want the sneaky attribute to be True for Thief. Someone instantiating Thief could pass sneaky = False in through the **kwargs, and if super() is called after making sneaky = True, then sneaky will end up being False. But if super() is called first, even if sneaky is passed in as False, then the Thief class would be overriding that value to True.

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

If you set self.sneaky = True before you use super(), if the super/parent class also sets self.sneaky, that class's value will be used, not yours.