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 trialLee McCormick
Python Web Development Techdegree Student 16,595 Pointsnot sure what to do on this
i think im doing what is in the video but this is not descriptive enough
class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
pass
def add_item(self, item)
super().add_item(item)
1 Answer
Valeriya Romashchenko
11,841 PointsIf you need to pass the second part of the challenge, you need to delete "pass" and keep the rest of the code. It passes the challenge, be careful though with indentations and etc. You miss the colon after add_item function in the SortedInventory
class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
def add_item(self, item):
super().add_item(item)
David Capella
4,126 PointsDavid Capella
4,126 PointsQuick question, Why don't you have to pass self in
super().add_item(item)
?Valeriya Romashchenko
11,841 PointsValeriya Romashchenko
11,841 PointsIt is a very interesting question. I checked possible forums/resources and etc. So, the primary function of the super() in simple words:
http://www.pythonforbeginners.com/super/working-python-super-function
when you call super() without any arguments you refer to the base class, the first class which could be a parent for a lot of instances. Every Instance is also a class and could be a parent. If you want to create a new Instance of the Instance of the first primary class and want to refer to the methods exactly of that instance, you need to pass the name of that instance and "self". If you don't you will always refer to the first primary class. As soon as we work only with one primary class and first "generation if Instances", we don't need additionally refer with "self" to that Primary class.
It is how I understand that. I recommend you to read some tutorials as well and if you have something to add, please share.
Kenneth Love , if you see this discussion, couldn't you please comment as well, if we are correct?