In this article we will look at the method rewrite in Python, some friends may have just come into contact with Python, the programming language, for
python rewrite This aspect of knowledge is relatively small, not clear about the method rewrite in Python knowledge. In the next article, let's take a look at a way to rewrite the method that
Python overrides the parent class .
Method overrides
If the functionality of your parent's methods does not meet your needs, you can override the methods of your parent class in subclasses :
The example python overrides the parent class method is as follows
#!/usr/bin/python#-*-Coding:utf-8-*-class Parent: # defines the parent class def myMethod (self): print ' calls the parent class method ' class child ( Parent): # definition Subclass def myMethod (self): print ' call subclass method ' C = Child () # Subclass Instance C.mymethod () # Subclass Call override method
Execute the above code to output the result as follows:
Calling Subclass Methods