[PYTHON] Method overriding and super

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

Method overriding and super
Perturbation development and simulation Perturbation method
Cumulative sum and potato method
Class inheritance and super functions
Use instance method and class method properly
Normalization method (encoding) and reversion (decoding)
Anomaly detection introduction and method summary
[Python] Reasons for overriding using super ()
[Python] Difference between function and method
[Python] Difference between class method and static method
[pandas] .csv file reading and display method