Python base-class function overload and call instance analysis, python instance analysis
This document describes how to reload and call Python basic functions. Share it with you for your reference. The specific analysis is as follows:
I have not been familiar with the Python language for a long time. I am not very familiar with many features of this language, and I still do not know many usage methods. Today, I want to write a function call in the inheritance of Python object-oriented programming. Share and make progress together.
Because I have been familiar with Java and C ++ before, I have been familiar with all object-oriented ideas. Here, we will not repeat what object-oriented means. Let's go directly to the code! Let's see how to call the inheritance and base-class functions in Python ~
First, it is the base class file base. py
Copy codeThe Code is as follows :'''
Created on Dec 18,201 4
@ Author: raul
'''
Class animal (object ):
'''
Classdocs
'''
Def _ init _ (self ):
'''
Constructor
'''
Print 'animal init'
Def say (self ):
Print 'animal say'
Then, it is the child. py subclass file.
Copy codeThe Code is as follows :'''
Created on Dec 18,201 4
@ Author: raul
'''
From inheritance. base import animal
Class cat (animal ):
'''
Classdocs
'''
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 init
Cat init
Animal say
Cat say
This indicates that our inheritance and function call are OK.
This example is relatively simple, but I have basically understood the reload and call of Python-based functions. I hope you can give a similar picture.
I hope this article will help you with Python programming.