Python(二十一)多态

Posted on 2021-04-27 16:02  MissRong  阅读(44)  评论(0)    收藏  举报

Python(二十一)多态

class A:
    def fun(self):
        print("A类的方法")
class B:
    def fun(self):
        print("B类的方法")
class C:
    def test(self, obj):
        obj.fun()
if __name__ == "__main__":
    a = A()
    b = B()
    c = C()
    #鸭子类型
    c.test(a)

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3