What is the use of python partial function
This article is to share with you about the use of python partial functions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
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, you can call the partial function without specifying GaryFun (age = 13). Thank you for reading! This is the end of this article on "what is the use of python partial function". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!