This article mainly introduces the Python polymorphism and provides an in-depth analysis of the principles and implementation methods of Python polymorphism in Object-Oriented Programming in the form of examples, for more information about Python polymorphism, see the example in this article. Share it with you for your reference. The details are as follows:
#! /Usr/bin/env python # polymorphism in python # class base (object): "" base class "" def _ init _ (self, name): self. name = name def printest (self): print "base class:", self. nameclass subclass1 (base): "sub class 1" def printest (self): print "sub class 1:", self. nameclass subclass2 (base): "sub class 2" def printest (self): print "sub class 2:", self. nameclass subclass3 (base): "sub class 3" passdef testFunc (o): o. printest () if _ name _ = "_ main _": testFunc (subclass1 ("1") testFunc (subclass2 ("2 ")) testFunc (subclass3 ("3 "))
I hope this article will help you with Python programming.