Yes it is, just use the name of the method, as you have written. Methods and functions are objects in Python, just like anything else, and you can pass them around the way you do variables. In fact, you can think about a method (or function) as a variable whose value is the actual callable code object.

Since you asked about methods, I'm using methods in the following examples, but note that everything below applies identically to functions (except without the self parameter).

To call a passed method or function, you just use the name it's bound to in the same way you would use the method's (or function's) regular name:

def method1(self):
    return 'hello world'

def method2(self, methodToRun):
    result = methodToRun()
    return result

obj.method2(obj.method1)

Note: I believe a __call__() method does exist, i.e. you could technically do methodToRun.__call__(), but you probably should never do so explicitly. __call__() is meant to be implemented, not to be invoked from your own code.

If you wanted method1 to be called with arguments, then things get a little bit more complicated. method2 has to be written with a bit of information about how to pass arguments to method1, and it needs to get values for those arguments from somewhere. For instance, if method1 is supposed to take one argument:

def method1(self, spam):
    return 'hello ' + str(spam)

then you could write method2 to call it with one argument that gets passed in:

def method2(self, methodToRun, spam_value):
    return methodToRun(spam_value)

or with an argument that it computes itself:

def method2(self, methodToRun):
    spam_value = compute_some_value()
    return methodToRun(spam_value)

You can expand this to other combinations of values passed in and values computed, like

def method1(self, spam, ham):
    return 'hello ' + str(spam) + ' and ' + str(ham)

def method2(self, methodToRun, ham_value):
    spam_value = compute_some_value()
    return methodToRun(spam_value, ham_value)

or even with keyword arguments

def method2(self, methodToRun, ham_value):
    spam_value = compute_some_value()
    return methodToRun(spam_value, ham=ham_value)

If you don't know, when writing method2, what arguments methodToRun is going to take, you can also use argument unpacking to call it in a generic way:

def method1(self, spam, ham):
    return 'hello ' + str(spam) + ' and ' + str(ham)

def method2(self, methodToRun, positional_arguments, keyword_arguments):
    return methodToRun(*positional_arguments, **keyword_arguments)

obj.method2(obj.method1, ['spam'], {'ham': 'ham'})

In this case positional_arguments needs to be a list or tuple or similar, and keyword_arguments is a dict or similar. In method2 you can modify positional_arguments and keyword_arguments (e.g. to add or remove certain arguments or change the values) before you call method1.

Answer from David Z on Stack Overflow
Top answer
1 of 9
346

Yes it is, just use the name of the method, as you have written. Methods and functions are objects in Python, just like anything else, and you can pass them around the way you do variables. In fact, you can think about a method (or function) as a variable whose value is the actual callable code object.

Since you asked about methods, I'm using methods in the following examples, but note that everything below applies identically to functions (except without the self parameter).

To call a passed method or function, you just use the name it's bound to in the same way you would use the method's (or function's) regular name:

def method1(self):
    return 'hello world'

def method2(self, methodToRun):
    result = methodToRun()
    return result

obj.method2(obj.method1)

Note: I believe a __call__() method does exist, i.e. you could technically do methodToRun.__call__(), but you probably should never do so explicitly. __call__() is meant to be implemented, not to be invoked from your own code.

If you wanted method1 to be called with arguments, then things get a little bit more complicated. method2 has to be written with a bit of information about how to pass arguments to method1, and it needs to get values for those arguments from somewhere. For instance, if method1 is supposed to take one argument:

def method1(self, spam):
    return 'hello ' + str(spam)

then you could write method2 to call it with one argument that gets passed in:

def method2(self, methodToRun, spam_value):
    return methodToRun(spam_value)

or with an argument that it computes itself:

def method2(self, methodToRun):
    spam_value = compute_some_value()
    return methodToRun(spam_value)

You can expand this to other combinations of values passed in and values computed, like

def method1(self, spam, ham):
    return 'hello ' + str(spam) + ' and ' + str(ham)

def method2(self, methodToRun, ham_value):
    spam_value = compute_some_value()
    return methodToRun(spam_value, ham_value)

or even with keyword arguments

def method2(self, methodToRun, ham_value):
    spam_value = compute_some_value()
    return methodToRun(spam_value, ham=ham_value)

If you don't know, when writing method2, what arguments methodToRun is going to take, you can also use argument unpacking to call it in a generic way:

def method1(self, spam, ham):
    return 'hello ' + str(spam) + ' and ' + str(ham)

def method2(self, methodToRun, positional_arguments, keyword_arguments):
    return methodToRun(*positional_arguments, **keyword_arguments)

obj.method2(obj.method1, ['spam'], {'ham': 'ham'})

In this case positional_arguments needs to be a list or tuple or similar, and keyword_arguments is a dict or similar. In method2 you can modify positional_arguments and keyword_arguments (e.g. to add or remove certain arguments or change the values) before you call method1.

2 of 9
42

Yes it is possible. Just call it:

class Foo(object):
    def method1(self):
        pass
    def method2(self, method):
        return method()

foo = Foo()
foo.method2(foo.method1)
🌐
Reddit
reddit.com › r/learnpython › pass a function into another function as an argument, with some but not all of the arguments?
r/learnpython on Reddit: Pass a function into another function as an argument, with some but not all of the arguments?
October 31, 2022 -

Hello, I am new to python, and am trying to learn as I go for my machine learning class. In order to make some of my assignment work, I need to be able to pass a function in as an argument to another function, but have some of the arguments already filled out.

So for example, let’s say I wanted to pass the function “foo” to use in a function “bar”. Lets assume that foo takes the arguments a, b, and c. I could write

bar(foo)

but in order to call foo, I would need a, b and c in bar.

alternatively, I could write

bar(foo(a, b, c))

but this is going to pass in as a value, and I need all 3 values.

Let’s say I have a and b to pass in, but c is calculated within bar. Is there a way to do this so I can give bar a and b, but not c?

edit: I figured it out! He just wanted me to create a lambda function that passes the arguments into the function, and then pass that lambda as the argument.

Discussions

Some way to get arguments of current function for passing along to another function even when not using *args/**kw
Often times I have a function that does not make use of *args/**kw for various reasons but still needs to pass along all arguments to another function. An example would be: def other_fun(a, b, c=7, d=9): ... def … More on discuss.python.org
🌐 discuss.python.org
0
1
June 10, 2024
Python: passing a function with parameters as parameter - Stack Overflow
287 Passing functions with arguments to another function in Python? More on stackoverflow.com
🌐 stackoverflow.com
November 7, 2011
Pass a function into another function as an argument, with some but not all of the arguments?
See "partial" from the functools module A partial function is pretty much a function with some of its arguments filled in More on reddit.com
🌐 r/learnpython
7
1
October 31, 2022
Function parameter as a tuple
I'd say that function arguments are already a tuple (when currying is not involved). Just not a first order one in most languages. Now that you mention it, treating them differently from other tuples might actually be the strange thing. At first glance, anyway. More on reddit.com
🌐 r/ProgrammingLanguages
77
54
December 6, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › python › passing-function-as-an-argument-in-python
Passing function as an argument in Python - GeeksforGeeks
July 12, 2025 - Explanation: lambda x: x ** 2 is passed to fun(), which squares the input 5 to produce 25. A wrapper function (decorator) enhances another function's behavior without modifying it.
🌐
Python Course
python-course.eu › python-tutorial › passing-arguments.php
25. Passing Arguments | Python Tutorial | python-course.eu
November 8, 2023 - Let's assume, we are passing a ... a look at a function which has no side effects. As a new list is assigned to the parameter list in func1(), a new memory location is created for list and list becomes a local variable....
🌐
AskPython
askpython.com › home › python: how to pass a function as an argument?
Python: How to pass a function as an argument? - AskPython
July 11, 2021 - Like user-defined and lambda functions we can also pass an operator function as an argument to another function. Here we will be using operator.mul() function from the operator module and pass it to the reduce() function which is defined in ...
🌐
W3Schools
w3schools.com › python › gloss_python_function_arguments.asp
Python Function Arguments
Python Functions Tutorial Function Call a Function *args Keyword Arguments **kwargs Default Parameter Value Passing a List as an Argument Function Return Value The pass Statement i Functions Function Recursion
Find elsewhere
🌐
Python Morsels
pythonmorsels.com › passing-functions-arguments-other-functions
Passing functions as arguments to other functions - Python Morsels
June 3, 2021 - This get_two function accepts a function as an argument: >>> def get_two(func, thing): ... return func(thing), func(thing) ... The one thing that you can do with every function is call it.
🌐
Educative
educative.io › answers › how-to-pass-a-parameter-to-a-function-in-python
How to pass a parameter to a function in Python
The same is done when passing their arguments. Any parameter given to a function must have its corresponding positional argument. Let’s define a function with two parameters, first_name and last_name. Now let’s see what happens when we do not give corresponding positional arguments to the parameters of the function. ... Notice that the code above gives an error message that reads as follows.
🌐
Trey Hunner
treyhunner.com › 2020 › 01 › passing-functions-as-arguments
Passing a function as an argument to another function in Python
January 14, 2020 - We could pass this length_and_... on the fact that Python’s ordering operators do deep comparisons. The key argument accepted by sorted, min, and max is just one common example of passing functions into function...
🌐
TutorialsPoint
tutorialspoint.com › How-to-pass-Python-function-as-a-function-argument
How to pass Python function as a function argument?
April 11, 2025 - The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None. def function_name( parameters ): "function_docstring" function_suite return [expression] By default, parameters have a positional behavior and you need to inform them in the same order that they were defined. Once the function is defined, you can execute it by calling it from another function or directly from the Python prompt.
🌐
Python.org
discuss.python.org › python help
Some way to get arguments of current function for passing along to another function even when not using *args/**kw - Python Help - Discussions on Python.org
June 10, 2024 - An example would be: def other_fun(a, b, c=7, d=9): ... def myfun(a, b, c=7, d=9): v = other_fun(a, b, c=c, d=d) # do some other post processing of v, often times depending on the input arguments ...
🌐
Qissba
qissba.com › home › blog › parameter passing methods in python | 3 important method or techniques | cbse class 12
Parameter Passing methods in Python | 3 Important Method or Techniques | CBSE Class 12 Qissba -
May 10, 2025 - ... In this example, the string "Alice" is passed as an argument to the greet function. The function takes this argument and uses it to print out the greeting message. In Python, you can pass a function parameter to another function by passing ...
🌐
IncludeHelp
includehelp.com › python › function-as-argument-example.aspx
Python Passing a function as an argument
April 25, 2025 - Consider the below syntax (or, approach) to pass a function as an argument: def func1(): body def func2(): body # Calling func2(func1) Here, we are defining two function foo() and koo(), function koo() will take an argument x that will be a function while calling.
🌐
Javatpoint
javatpoint.com › pass-function-as-parameter-python
Pass function as parameter python - Javatpoint
Pass function as parameter python with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.
🌐
py4u
py4u.org › blog › python-passing-a-function-with-parameters-as-parameter
How to Pass a Python Function with Parameters as Another Function's Parameter: A Step-by-Step Guide
The solution is to pass the function without invoking it but still associate it with its parameters. Let’s explore three methods to do this. A lambda function is an anonymous, one-line function that can capture parameters and return a callable object. We can use a lambda to "wrap" the target function with its parameters, creating a new function that requires no arguments (or additional arguments) when invoked. Let’s modify the execute_function example to work with greet(name) using a lambda:
🌐
Programiz
programiz.com › python-programming › function-argument
Python Function Arguments (With Examples)
Both values are passed during the function call. Hence, these values are used instead of the default values. ... 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.
🌐
Studytonight
studytonight.com › python-howtos › how-to-pass-a-method-as-an-argument-in-python
How to Pass a Method as an Argument in Python? - Studytonight
February 23, 2021 - Python implements the map() function where the first parameter is a function and the second is iterable. In this example, the function call passes the function sqr(x) as a function argument using the map method.