Python function overloading mechanism?

First of all, what is overloaded?

Overloaded mainly to solve two problems. 1. Variable parameter type. 2. Variable number of arguments.

Further, a fundamental design principle that only when the two functions except for the number of parameters and parameter types, its function is identical, only this time using the heavy load function, if the function is actually two different functions, it is not It should be heavy-duty use, but should use a different name of a function.

For Case 1, the same function function, but different parameter types, how to deal with python? The answer is no need to deal with, because the python can accept any type of argument, if the function is a function of the same, different types of parameters in python is likely to be the same code, there is no need to make two different functions.

So 2, the same as in the case of function function, but a different number of parameters, how to deal with python? As we all know, the answer is the default parameter. For those missing parameter is set to default parameters to solve the problem. Because you assume the same function function, then those missing parameter after all, is the need to use.

So we do not need natural python function overloading.

Guess you like

Origin www.cnblogs.com/wenm1128/p/11671526.html