First, overview:
The specific meanings of the Python apply function are as follows:
the Apply (func [, args [, Kwargs]]) function is used to indirectly invoke a function when a function parameter already exists in a tuple or dictionary . Args is a tuple that contains the arguments passed by position that will be supplied to the function. If args is omitted, no arguments are passed, and Kwargs is a dictionary containing the keyword arguments.
The return value of apply () is the return value of the Func (), and the element parameters of apply () are ordered, and the order of the elements must match the order of the Func () Form parameters
Second, use example:
Here are a few examples to explain the use of apply in detail:
1. Assume that a method with no parameters is executed:
Def say (): print ' say in ' Apply (say)
The result of the output is ' say in '
2. The function only takes the parameters of the tuple:
Def say (A, b): Print A, b apply (say, ("Hello", "Zhang San Python"))
The result of the output is Hello, Zhang San python
3. Function with keyword parameter:
def say (a=1,b=2): Print a, b def haha (**kw): #say (kw) apply (say, (), kw) print haha (a= ' a ', b= ' B ')
The result of the output is: A, b