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 trialSohail Mirza
Python Web Development Techdegree Student 5,158 Pointswhy 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
231,275 PointsIt 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
Python Web Development Techdegree Student 5,158 PointsSohail Mirza
Python Web Development Techdegree Student 5,158 PointsHi 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
231,275 PointsSteven Parker
231,275 PointsHere's an example where both a number and a string are initialized:
This method will have a "score" and "message" attribute, and neither need be passed as arguments.