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