ScanSkill

apply

This apply() function returns the result of a function or class object called with supplied arguments.

Syntax

apply(function, args[, kwargs])

Here,

  • function: Required. The function argument must be a callable object (a user-defined or built-in function or method, or a class object).
  • args: Required. A sequence of positional arguments.
  • kwargs: Optional. The kwargs argument must be a dictionary whose keys are strings. It specifies keyword arguments to be added to the end of the argument list.

Note: This function is obsolete. Use function(*args, **kwargs) instead of apply(function, args, kwargs).

Examples

>>> def fun1(a, b):
...     return a, b
...
>>> apply(func1, (7, 13))
(7, 13)
>>> def func2(a, b, c=None):
...     return a, b, c
...
>>> apply(func2, (1, 2), {'c': 3})
(1, 2, 3)