[PYTHON] setter and getter
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)
#If you want to access the variable using getter or setter, before the variable name_Put on
self._enable_auto_run = enable_auto_run
#Before the variable name to completely shield from the outside_Attach two
#self.__enable_auto_run = enable_auto_run
@property
def enable_auto_run(self):
return self._enable_auto_run
@enable_auto_run.setter
def enable_auto_run(self,is_enable):
self._enable_auto_run = is_enable
#Method override
def run(self):
print('fast fun')
car = Car()
car.run()
toyotar_car = ToyotaCar('Lexus')
toyotar_car.enable_auto_run = True
print(toyotar_car.enable_auto_run)
run
True