"ZH cheese" Why doesn't python need function overloading?

Source: Internet
Author: User
What is the function overload?

function overloading is mainly to solve two problems

  1. Variable parameter types
  2. 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.

For question 1, the function is the same, but the parameter types are different, how does python handle it? The answer is no processing, because Python can accept any type of argument, if the function is the same function, then the different parameter types in Python is likely to be the same code, there is no need to make two of different functions.

For question 2, the function is the same, but the number of parameters is different, how does python handle it? The answer is the default parameter, because the function is the same function, then the default parameter must be used.

In summary, problem 1 and Problem 2 have a solution, so Python naturally does not require function overloading.

Reference: Python does not require function overloading

"ZH cheese" Why doesn't python need function overloading?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.