To expand a little on the other answers:

In the line:

def wrapper(func, *args):

The * next to args means "take the rest of the parameters given and put them in a list called args".

In the line:

    func(*args)

The * next to args here means "take this list called args and 'unwrap' it into the rest of the parameters.

So you can do the following:

def wrapper1(func, *args): # with star
    func(*args)

def wrapper2(func, args): # without star
    func(*args)

def func2(x, y, z):
    print x+y+z

wrapper1(func2, 1, 2, 3)
wrapper2(func2, [1, 2, 3])

In wrapper2, the list is passed explicitly, but in both wrappers args contains the list [1,2,3].

Answer from itsadok on Stack Overflow
Top answer
1 of 6
296

To expand a little on the other answers:

In the line:

def wrapper(func, *args):

The * next to args means "take the rest of the parameters given and put them in a list called args".

In the line:

    func(*args)

The * next to args here means "take this list called args and 'unwrap' it into the rest of the parameters.

So you can do the following:

def wrapper1(func, *args): # with star
    func(*args)

def wrapper2(func, args): # without star
    func(*args)

def func2(x, y, z):
    print x+y+z

wrapper1(func2, 1, 2, 3)
wrapper2(func2, [1, 2, 3])

In wrapper2, the list is passed explicitly, but in both wrappers args contains the list [1,2,3].

2 of 6
28

The simpliest way to wrap a function

    func(*args, **kwargs)

... is to manually write a wrapper that would call func() inside itself:

    def wrapper(*args, **kwargs):
        # do something before
        try:
            return func(*a, **kwargs)
        finally:
            # do something after

In Python function is an object, so you can pass it's name as an argument of another function and return it. You can also write a wrapper generator for any function anyFunc():

    def wrapperGenerator(anyFunc, *args, **kwargs):
        def wrapper(*args, **kwargs):
            try:
                # do something before
                return anyFunc(*args, **kwargs)
            finally:
                #do something after
        return wrapper

Please also note that in Python when you don't know or don't want to name all the arguments of a function, you can refer to a tuple of arguments, which is denoted by its name, preceded by an asterisk in the parentheses after the function name:

    *args

For example you can define a function that would take any number of arguments:

    def testFunc(*args):
        print args    # prints the tuple of arguments

Python provides for even further manipulation on function arguments. You can allow a function to take keyword arguments. Within the function body the keyword arguments are held in a dictionary. In the parentheses after the function name this dictionary is denoted by two asterisks followed by the name of the dictionary:

    **kwargs

A similar example that prints the keyword arguments dictionary:

    def testFunc(**kwargs):
        print kwargs    # prints the dictionary of keyword arguments
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_arguments.asp
Python Function Arguments
An argument is the actual value ... name) my_function("Emil") # "Emil" is an argument ยท By default, a function must be called with the correct number of arguments....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-functions
Python Functions - GeeksforGeeks
After creating a function, call it by using the name of the functions followed by parenthesis containing parameters of that particular function. ... Arguments are values passed to a function when it is called.
Published ย  13 hours ago
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-function-examples-how-to-declare-and-invoke-with-parameters-2
Python Function Examples โ€“ How to Declare and Invoke with Parameters
August 24, 2021 - In this case, instead of just passing in values in the function call, you instead specify the name of the parameter and then the value you want to assign it, in the form of key = value.
๐ŸŒ
CodingNomads
codingnomads.com โ€บ how-to-call-a-function-in-python
How to Call a Function in Python
To execute a function, you need to call it. You do that by writing the function's name followed by opening and closing parentheses. If your function requires parameters, you need to pass the right amount of arguments in between the parentheses.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-call-functions-with-arguments-in-python-415175
How to call functions with arguments in Python | LabEx
Understanding these basic concepts will help you effectively use functions in your Python programs. The most common way to pass arguments to a function is by using positional arguments.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ function-argument
Python Function Arguments (With Examples)
Only one value is passed during the function call. So, according to the positional argument 2 is assigned to argument a, and the default value is used for parameter b.
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-call-a-function-with-argument-list-in-python-1
How to call a function with argument list in Python?
Use *args in a function definition to accept a variable number of arguments, and use the * operator in a function call to unpack an existing list or tuple into individual arguments.
๐ŸŒ
PyTutorial
pytutorial.com โ€บ how-to-call-a-function-in-python
PyTutorial | How to Call a Function in Python
February 4, 2026 - In this example, greet() is the function call. Python runs the code inside the greet function definition. The parentheses are crucial. They tell Python you want to execute the function. Forgetting them is a common mistake. Functions often need data to work with. This data is passed as arguments inside the parentheses.
๐ŸŒ
Guru99
guru99.com โ€บ home โ€บ python โ€บ how to call a function in python (example)
How to Call a Function in Python (Example)
August 12, 2024 - Step 5) Multiple Arguments can also be passed as an array. Here in the example we call the multiple args (1,2,3,4,5) by calling the (*args) function. Example: We declared multiple args as number (1,2,3,4,5) when we call the (*args) function; ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-define-and-call-functions-in-python
How to Define And Call Functions in Python
December 11, 2025 - To call a function in Python, you simply type the name of the function followed by parentheses (). If the function takes any arguments, they are included within the parentheses.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_functions.asp
Python Functions
In Python, a function is defined using the def keyword, followed by a function name and parentheses: ... This creates a function named my_function that prints "Hello from a function" when called.
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ calling-a-function
How to call a function in Python - Python Morsels
November 11, 2020 - To call a function in Python, write the function name followed by parentheses. If the function accepts arguments, pass the arguments inside the parentheses as you call the function.
๐ŸŒ
In Easy Steps
ineasysteps.com โ€บ home โ€บ a quick guide to python functions (with examples)
A quick guide to Python functions (with examples) - In Easy Steps
February 7, 2023 - Hereโ€™s an example of using arguments in a Python function: In this example, the function \add_numbers\ takes two arguments \a\ and \b\ and returns their sum. When the function is called, we pass the values \3\ and \5\ as arguments, and the ...
๐ŸŒ
KDnuggets
kdnuggets.com โ€บ 2023 โ€บ 02 โ€บ python-function-arguments-definitive-guide.html
Python Function Arguments: A Definitive Guide - KDnuggets
February 9, 2023 - If youโ€™d like the function to take in arguments, then the names of the arguments should be specified as parameters inside parentheses. After defining a function, you can call it with values for the parameters, called arguments.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ how to call a function in python?
How to Call a Function in Python? - Scaler Topics
February 2, 2024 - ... If you do not know how many arguments will be passed into your function, add a * before the parameter name in the function definition. This way, the function will receive a tuple of arguments and can access the items accordingly: ... Arbitrary ...
Top answer
1 of 2
1
In Python, you can call a function by using its name followed by parentheses `()` and passing in any required arguments. Here's an example:*Example: Calling a Simple Function*```# Define a simple functiondef greet(name): print("Hello, " + name + "!")# Call the functiongreet("John") # Output: Hello, John!```In this example:1. We define a function `greet` that takes one argument `name`.2. We call the function by using its name `greet` followed by parentheses `()` and passing in the argument `"John"`.*Example: Calling a Function with Multiple Arguments*```# Define a function with multiple argumentsdef add_numbers(a, b): return a + b# Call the functionresult = add_numbers(5, 3)print(result) # Output: 8```In this example:1. We define a function `add_numbers` that takes two arguments `a` and `b`.2. We call the function by using its name `add_numbers` followed by parentheses `()` and passing in the arguments `5` and `3`.*Example: Calling a Function with Default Argument Values*```# Define a function with default argument valuesdef greet(name = "World"): print("Hello, " + name + "!")# Call the function without passing an argumentgreet() # Output: Hello, World!# Call the function with a custom argumentgreet("John") # Output: Hello, John!```In this example:1. We define a function `greet` with a default argument value `"World"` for the `name` parameter.2. We call the function without passing an argument, and it uses the default value.3. We call the function with a custom argument, and it overrides the default value.
2 of 2
1
To call a function in Python, use its name followed by parentheses. Example:    function_name(arguments)Explanation:A function must first be defined using def. Then, you can call it by writing its name with parentheses, optionally passing arguments if required. Example:def greet(name):    print("Hello" + name)greet("Jamie")Output:Hello Jamie
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ calling-a-function-in-python
Calling a Function in Python
March 25, 2026 - The function call must match the ... are 30 years old! ... Function calling in Python is straightforward using the function_name(arguments) syntax....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-define-and-call-a-function-in-python
How to Define and Call a Function in Python - GeeksforGeeks
July 23, 2025 - ... def fun(): print("Welcome to ... to it when called. To call a function in Python, we definitely type the name of the function observed via parentheses ()....