Overloading and rewriting, which are two new concepts, are two concepts that make it easy for us to confuse each other. 1. overloading (overloading method)
is in a class, the method has the same name, and the parameters are different. What about the return type? can be the same or different. Overloading is a means for a class to handle different types of data in a uniform manner.
function overloading is mainly to solve two problems.
1. variable parameter type.
2. The number of variable parameters.
In addition, a basic design principle is that only if the function of the two functions is identical except for the parameter type and the number of parameters, then the function overload is used, if the function of two functions is different, then the overload should not be used, but a function with different names should be used.
Okay, so for scenario 1, the functions are the same, but the parameter types are different, how does python handle it? The answer is that there is no need to deal with it, because Python can accept any type of argument, and if the function is the same, then the different parameter types are probably the same code in Python, and there is no need to make two different functions.
So for scenario 2, the function is the same, but the number of parameters is different, how does python handle it? As you know, the answer is the default parameter. Setting the default parameters for those missing parameters solves the problem. Because you assume that functions function the same, then those missing parameters are needed.
Well, given that scenario 1 and Scenario 2 have a solution, Python naturally does not need function overloading.
2. Methods override (Overiding method)
Subclasses do not want to inherit the method of the parent class intact, but want to make some changes, this need to adopt the method of rewriting. Method overrides are also called method overrides
Python overloads and overrides of the "difference"