Python 类的多态
Posted 庖丁解牛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 类的多态相关的知识,希望对你有一定的参考价值。
#python的多态 class Dog(): def eat(self): print("i am dog , eat something . ") class Cat(): def eat(self): print("i am cat , eat somthing .") #多态的调用形式 def animal_eat(one): one.eat() d = Dog() c = Cat() animal_eat(d) animal_eat(c) ‘‘‘ python本身属于弱类型语言,变量本身没有类型 python的多态并非是里氏替换原则,仅仅是因为这个对象恰好有这个方法就行,甚至不需要存在继承 ‘‘‘
以上是关于Python 类的多态的主要内容,如果未能解决你的问题,请参考以下文章