Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the partial function of python

Shulou Source: shulou.com Published: 2022-05-31 10:47:47 10月04日 Update

This article mainly introduces the relevant knowledge of what the python partial function is, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will have something to gain after reading this python partial function, let's take a look at it.

1. The partial function is the secondary encapsulation of the original function, which binds some parameters of the existing function to the specified value in advance to obtain a new function.

2. To define a partial function, you need to use the partial keyword (located in the functools module).

Grammar

Partial function name = partial (func, * args, * * kwargs)

Example

From functools import partial # imports the partial function in the functools module # defines an original function def display (name,age): print ("name:", name, "age:", age) # defines a partial function, which encapsulates the display () function and sets the default parameter GaryFun = partial (display,name = 'Gary') for the name parameter. Because the name parameter already has a default value, when calling the partial function You can not specify GaryFun (age = 13). This is the end of the article on "what is the partial function of python?". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what is the partial function of python". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Function parameter knowledge content module article encapsulation original value key keyword example easy to operate article easy to understand more see industry grammar information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Xiaomi Huawei Shulou Tech Info