Python apply function:
The apply (func [, args [, kwargs]) function is used to call a function indirectly when a function parameter already exists in a tuple or dictionary. Args is a tuple that contains parameters that will be provided to the function by location. If args is omitted, no parameters will be passed. kwargs is a dictionary containing key parameters.
The return value of apply () is the return value of func (). The element parameters of apply () are ordered, and the element order must be consistent with the order of parameters in func () format.
The following is a detailed example:
1. Assume that the execution of the method without parameters is performed.
Def say ():
Print 'say in'
Apply (say)
The output result is 'say in'
2. The function only includes the parameters of the tuples.
Def say (a, B ):
Print a, B
Apply (say, ("hello", "Old Wang python "))
The output is hello, Old Wang python.
3. The function has a 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 output result is: a, B