Python之多态案例
Posted zhzhang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python之多态案例相关的知识,希望对你有一定的参考价值。
class Canvas: def draw_pic(self, shape): print(‘--start draw--‘) shape.draw(self) class Rectangle: def draw(self, canvas): print(‘draw rectangle on %s‘ % canvas) class Triangle: def draw(self, canvas): print(‘draw triangle on %s‘ % canvas) class Circle: def draw(self, canvas): print(‘draw circle on %s‘ % canvas) c = Canvas() c.draw_pic(Rectangle()) c.draw_pic(Triangle()) c.draw_pic(Circle())
谢谢!
以上是关于Python之多态案例的主要内容,如果未能解决你的问题,请参考以下文章