How do derived class constructors work in python?

后端 未结 2 2006
情深已故
情深已故 2021-02-05 05:49

I have the following base class:

class NeuralNetworkBase:
    def __init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs):
        self.inputLayer         


        
2条回答
  •  Happy的楠姐
    2021-02-05 06:41

    You will have to put this in the __init__() method of NeuralNetworkBackPropagation, that is to call the __init__() method of the parent class (NeuralNetworkBase):

    NeuralNetworkBase.__init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs)
    

    The constructor of the parent class is always called automatically unless you overwrite it in the child class. If you overwrite it in the child class and want to call the parent's class constructor as well, then you'll have to do it as I showed above.

提交回复
热议问题