Python Object-Oriented Python Inheritance Multiple Superclasses

Horatiu Banciu
Horatiu Banciu
11,360 Points

super in a class with no parrent class

Ok soo in the Sneaky class in the init method there's this super call

class Sneaky:
    sneaky = True

    def __init__(self, sneaky=True, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.sneaky = sneaky

    def hide(self, light_level):
        return self.sneaky and light_level < 10

but there's no parent class so why does he use it? is he trying to call the __init__ method of the object class? is there any reason at all to do that?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 56,649 Points

Good question! Kenneth designed the class Sneaky so that it can be used as a “mix-in” class. As a mix-in class, it is intended to be used before other inherited classes and not as the sole inherited class. Without the super(), any __init__ in a class following sneaky would not be run.

Post back if you need more help. Good luck!!!