python为什么没有overload

https://stackoverflow.com/questions/6434482/python-function-overloading

Why Not Overloading?

First one needs to understand the concept of overloading and why it's not applicable to python.

When working with languages that can discriminate data types at compile-time, selecting among the alternatives can occur at compile-time. The act of creating such alternative functions for compile-time selection is usually referred to as overloading a function. (Wikipedia)

Python is a dynamically typed language, so the concept of overloading simply does not apply to it. However, all is not lost, since we can create such alternative functions at run-time:

In programming languages that defer data type identification until run-time the selection among alternative functions must occur at run-time, based on the dynamically determined types of function arguments. Functions whose alternative implementations are selected in this manner are referred to most generally as multimethods. (Wikipedia)

So we should be able to do multimethods in python or, as it is alternatively called, multiple dispatch.

原文地址:https://www.cnblogs.com/andy-0212/p/10062948.html