代码示例
# -*- coding: utf-8 -*- import abc class Animal(abc.ABC): """动物类 抽象类""" @abc.abstractmethod def eat(self): """吃饭饭""" @abc.abstractmethod def sleep(self): """睡觉觉""" class Dog(Animal): """狗狗类 实现类""" def sleep(self): print("狗狗睡觉啦") def eat(self): print("狗狗吃饭啦") class Cat(Animal): """猫猫类 实现类""" def sleep(self): print("猫猫睡觉啦") def eat(self): print("猫猫吃饭啦") if __name__ == '__main__': dog = Dog() dog.sleep() # 狗狗睡觉啦 cat = Cat() cat.sleep() # 猫猫睡觉啦