Overloading of base class functions and invocation of base class functions in Python python

Source: Internet
Author: User

It's not long enough to touch the Python language, and many of the features of the language are not well understood, and many usages are not yet known. Today I want to write a function call in the inheritance of Python object-oriented programming. Share it and make progress together.

Because of previous exposure to Java and C + +, all of the ideas for object-oriented are already well-known. There is no longer a repeat of what object-oriented is. Let's go straight to the code! See how calls to inherited and base class functions are called in Python ~

First, it is the base class file base.py

"' Created on Dec, 2014@author:raul" Class Animal (object):    '    classdocs    '    def __init__ (self):        '''        Constructor        '        print ' animal init '            def say (self):        print ' animal say '

Then, is the subclass file child.py

"' Created on Dec, 2014@author:raul" from inheritance.base import Animalclass cat (Animal):    '    classdocs< c3/> "    def __init__ (self):" '        Constructor ' "        #         animal.__init__ ()        animal.__init__ (self) )        print ' Cat init '            def say (self):        Animal.say (self)        print ' cat say ' if __name__ = = ' __main__ ':    c = Cat ()    C.say ()    

After running, you can see the output as follows:

Animal Initcat Initanimal Saycat say

This means that our inheritance and the invocation of the function are all OK.

Overloading of base class functions and calls to base class functions in Python python

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.