from abc import abstractmethod, ABCMeta # 抽象类是不能实例化的类 class Talker(metaclass=ABCMeta): @abstractmethod # 标记为抽象方法,子类必须实现这方法 def talk(self): pass class Said(Talker): def talk(self): # 子类实现抽象类的方法 print('talk something') class Herring: pass # def talk(self): # print('Herring') said = Said() said.talk() print(isinstance(said, Talker)) h = Herring() print(Talker.register(Herring)) # 注册使Herring成为Talker的对象 print(isinstance(h, Talker)) print(issubclass(Herring, Talker)) # h.talk() # 区别继承,这里就不能调用父类的方法,抽象类失去意义