class Car(object):
    def __init__(self,model=None):
        self.model=model
    def run(self):
        print('run')
class ToyotaCar(Car):
    def __init__(self, model,enable_auto_run = False):
        #self.model =It can also be written as a model, but the parent method can be read using super.
        super().__init__(model)
        self.enable_auto_run = enable_auto_run
    #Method override
    def run(self):
        print('fast fun')
car = Car()
car.run()
toyotar_car = ToyotaCar('Lexus')
toyotar_car.run()
print(toyotar_car.model)
output
run
fast fun
Lexus
        Recommended Posts