First, overview:
The specific meaning of the Python apply function is as follows:
Apply (func [, args [, Kwargs]]) functions are used to invoke functions indirectly when function arguments already exist in a tuple or dictionary . Args is a tuple that contains the arguments that are passed by location that will be supplied to the function. If args is omitted, no arguments are passed, Kwargs is a dictionary that contains the keyword parameters.
The return value of apply () is the return value of func (), the element parameter of the Apply () is ordered, and the order of the elements must be the same as the order of the Func () Form parameters
Second, the use of examples:
Here are a few examples to illustrate the use of apply in detail:
1, the assumption is that there are no parameters with the method:
Def say ():
print ' say in '
apply (say)
The result of the output is ' say in '
2, the function takes only the parameters of the tuple:
Def say (A, b):
print A, b
apply (say, ("Hello", "John Python")
The result of the output is Hello, John Python
3, function with keyword parameters:
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