Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Inheritance Super-Duper!

Kohei Ashida
Kohei Ashida
4,881 Points

Why don't you need "self" parameter?

Why don't you need "self" parameter when you call super() like super.init(self, name, **kwargs) instead of super().init(name, **kwargs)?

2 Answers

Steven Parker
Steven Parker
210,423 Points

They system adds the "self" parameter when the call is processed, it's not passed as an explicit argument. This is unrelated to the use of "super", and happens on any class method.

Steven Parker
Steven Parker
210,423 Points

The system's insertion of the "self" argument happens anytime you make a method call, whether it is done inside the same (or another) class or just in the outer code.

Kohei Ashida
Kohei Ashida
4,881 Points

Thanks Steven! Now I understood that the system's insertion happens anytime I make a method call but why don't you need "self" parameter when you define a method in another method like below.

class Sneaky:
    sneaky = True

    def __init__(self, sneaky=True, *args, **kwargs): # "self" parameter needed
        super().__init__(*args, **kwargs) # no "self" parameter needed
        self.sneaky = sneaky
Steven Parker
Steven Parker
210,423 Points

That second line is not a definition, it is calling the other method. The call is where you don't supply a "self" because the system will add it for you.

Kohei Ashida
Kohei Ashida
4,881 Points

Thank you for your explanation! Now I got it that I misunderstood the second line is the same thing as the "def" line.

Kohei Ashida
Kohei Ashida
4,881 Points

Thanks for quick response as always, Steven! So you're saying that the "self" parameter in the method is systematically added when the method itself is written in another method of a class?