Analysis of Python polymorphism instances

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.