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!

Kohei Ashida
Kohei Ashida
4,882 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
229,644 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
229,644 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,882 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
229,644 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,882 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,882 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?