class KitchenSink(Sink):
def init(self, basin, nozzle, trash_compactor=None):
super().init(basin, nozzle)
if trash_compactor:
self.trash_compactor = trash_compactor
I am so confused on what the purpose of the “if trash_compactor:” is. Why is there an empty if statement here. I’m not understanding this syntax please help TY!
Thank you for reading this. I have a quick question regarding using the super() function. Why doesn’t the example exercise use ‘self’ in the method that’s an attribute of super()?
Are you asking why we use super().init(potatoes, celery, onions) rather than super().init(self.potatoes, self.celery, self.onions)? If so, I have the same question.
I think it may be because the object has hasn’t been instantiated at the point of this function call yet but I am unsure
If the parent class has those attributes and the subclass has no need to override them, then all we’re doing with super() is instantiating those attributes in the parent class. They are still accessible to the subclass instance.
Can someone tell me please what exactly is wrong with the code above ? This is for the question 2 , of the Super() lesson , on the Inheritance and Polymorphism of the learn Python course. I checked the solution and as far as i can see it is exactly the same code, but maybe i am missing something.
Hi @mtf thank you for the prompt response and dedication to this community. We defined a KitchenSink class which inherited it’s definition from the Sink class. Could we pass a sink instance into our definition of KitchenSink when creating an instance of kitchen sink? Thus, taking an existing sink object and making it a kitchen sink.
All of the attributes of Sink are inherited by KitchenSink by virtue of passing it into the subclass definition. I don’t know enough about the inner workings of Python to explain how this works, but it does