Knowing the question: Why does Python not support function overloading?
Function overloading is mainly to solve two problems.
Okay, so for case 1, the function has the same function, but the parameter type is different, how does python handle it? The answer is that there is no need to deal with it at all, because python can accept any type of parameter. If the function of the function is the same, then different parameter types are likely to be the same code in python, and there is no need to make two different functions.
So for case 2, the function has the same function, but the number of parameters is different, how does python handle it? As you all know, the answer is the default parameters. The problem can be solved by setting the missing parameters as default parameters. Because you assume that the functions are the same, the missing parameters will eventually be needed.
Well, given that both cases 1 and 2 have solutions, python naturally does not need function overloading.
Recommended Posts