Abstract class

import abc


class Car(metaclass=abc.ABCMeta):
    def __init__(self,model=None):
        self.model = model

    @abc.abstractmethod
    def run(self):
        pass


class ToyotaCar(Car):
    def __init__(self, model,enable_auto_run=False):
        super().__init__(model)
        self.enable_auto_run = enable_auto_run
        
    #If you do not override it with the inherited class, an error will occur when you create the object
    def run(self):
        print('fast fun')


toyota_car = ToyotaCar('Lexus')

Recommended Posts

Abstract class
class
class
Class variables
Class inheritance
[Python] class, instance
About python, class
Page processing class
Class method static method
Proprietary exception class
JSON conversion class
#Python basics (class)