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 Advanced Objects Emulating Built-ins

Sohail Mirza
seal-mask
.a{fill-rule:evenodd;}techdegree
Sohail Mirza
Python Web Development Techdegree Student 5,158 Points

why don't we put slots as a argument

When Kenneth creates the Class inventory in the init method(function) he doesnt put slot as a argument. What is the logic behind this, is it because slot is referencing a list. Hope the question makes sense def init(self): self.slots = []

1 Answer

Steven Parker
Steven Parker
231,275 Points

It doesn't need to have "slots" as an argument, because on the next line it is being created (as "self.slots") and assigned an empty list to start with.

In this case it happens to be a list, but it's common for an "__init__" method to initialize class attributes which might be of any type.

Sohail Mirza
seal-mask
.a{fill-rule:evenodd;}techdegree
Sohail Mirza
Python Web Development Techdegree Student 5,158 Points

Hi Steven

Thanks for your reply. could you please expand what you mean when you said(with a example) but it's common for an "init" method to initialize class attributes which might be of any type.

Thanks

Steven Parker
Steven Parker
231,275 Points

Here's an example where both a number and a string are initialized:

    def __init__(self):
        self.score = 0
        self.message = "You win!"

This method will have a "score" and "message" attribute, and neither need be passed as arguments.