python四十五:归一化继承
生活随笔
收集整理的這篇文章主要介紹了
python四十五:归一化继承
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?類似java中的接口,一個類實現了某個接口,就必須實現這個接口中定義的方法。
from abc import ABC,abstractmethodclass Animal(ABC):@abstractmethoddef eat(self):passclass Dog(Animal):def swim(self):print("游泳")def eat(self):print("啃骨頭")class Cat(Animal):def catch(self):print("抓老鼠")def eat(self):print("吃魚")d = Dog() d.swim() d.eat()?
總結
以上是生活随笔為你收集整理的python四十五:归一化继承的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python四十四:面向对象特性:继承
- 下一篇: python四十六:继承顺序之线性顺序列