Partial function, partial derivative

Source: Internet
Author: User

Partial function, partial derivative

PythonFunctoolsThe module provides many useful functions, one of which is the Partial function ). Note that the partial function here is different from the partial function in the mathematical sense.

When introducing function parameters, we will talk about how to reduce the difficulty of function calling by setting the default values of parameters. This can also be done by partial functions.

Functools. partialIs to help us create a partial function, we do not need to define our ownInt2 (), You can directly use the following code to create a new functionInt2:

Import functoolsint2 = functools. partial (int, base = 2) int2 ('000000') # equivalent to int ('000000', base = 2)

When passed in:

Max2 = functools. partial (max, 10)

In fact10As* ArgsIs automatically added to the left, that is:

Max2 (5, 6, 7)
Equivalent:
Args = (10, 5, 6, 7) max (* args)
Summary

UseFunctools. partialYou can create a new function, which can fix some parameters of the original function, making it easier to call.

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.