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)
๐ŸŒ
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. It takes a function as an argument and calls it within the wrapper.
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
Passing a function with arguments as an argument of another function
You don't need to pass the function as a parameter of the second function. It should work without. If you absolutely HAVE to, I'm pretty sure you can pass X as a third argument and use that when you call the first function. More on reddit.com
๐ŸŒ r/learnpython
3
1
September 6, 2020
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 8, 2021
๐ŸŒ
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.

๐ŸŒ
Trey Hunner
treyhunner.com โ€บ 2020 โ€บ 01 โ€บ passing-functions-as-arguments
Passing a function as an argument to another function in Python
January 14, 2020 - There are actually quite a few functions built-in to Python that are specifically meant to accept other functions as arguments. The built-in filter function accepts two things as an argument: a function and an iterable.
๐ŸŒ
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. So this get_two function is assuming that func points to a function object or some other callable object (anything that you can call by putting parentheses after it). In Python you can pass function objects in to other functions.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-pass-Python-function-as-a-function-argument
How to pass Python function as a function argument?
April 11, 2025 - As variable in Python is a label or reference to the object in the memory, both the variables used as actual argument as well as formal arguments really refer to the same object in the memory. We can verify this fact by checking the id() of the passed variable before and after passing. In the following example, we are checking the id() of a variable. def testfunction(arg): print ("ID inside the function:", id(arg)) var = "Hello" print ("ID before passing:", id(var)) testfunction(var)
Find elsewhere
๐ŸŒ
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 - 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 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 ...
๐ŸŒ
Real Python
realpython.com โ€บ python-pass-by-reference
Pass by Reference in Python: Background and Best Practices โ€“ Real Python
October 21, 2023 - As you can see, the refParameter of squareRef() must be declared with the ref keyword, and you must also use the keyword when calling the function. Then the argument will be passed in by reference and can be modified in place. Python has no ref keyword or anything equivalent to it.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_function_passing_list.asp
Python Passing a List as an Argument
E.g. if you send a List as an argument, it will still be a List when it reaches the function: def my_function(food): for x in food: print(x) fruits = ["apple", "banana", "cherry"] my_function(fruits) Try it Yourself ยป ยท Python Functions Tutorial Function Call a Function Function Arguments *args Keyword Arguments **kwargs Default Parameter Value Function Return Value The pass Statement i Functions Function Recursion
๐ŸŒ
W3Schools
w3schools.com โ€บ Python โ€บ python_arguments.asp
Python Function Arguments
Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma. The following example has a function with one argument (fname).
๐ŸŒ
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 - These functions allow us to perform mathematical, relational, logical, or bitwise operations on a given list of arguments. Like user-defined and lambda functions we can also pass an operator function as an argument to another function.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ passing a function with arguments as an argument of another function
r/learnpython on Reddit: Passing a function with arguments as an argument of another function
September 6, 2020 -

I'm unsure about executing the following code to compute a numeric derivative. I've been able to pass func(*args, **kwargs) for a decorator before. However, I am having trouble carrying it out in this particular case:

def func(x):
    return x*(x-1)

def derivative(func, delta):
    
    return (func(x+delta)-func(x))/delta

derivative(func(1), 10^-2)

Right now I'm not passing anything correctly, but my other attempts haven't been successful so I'm just leaving the code in the way I wanted to execute it initially. How would I go about passing the x argument into the derivative?

๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ arguments-in-python
5 Types of Python Function Arguments | Built In
First, during the function call, all arguments are given as positional arguments. Values passed through arguments are passed to parameters by their position. 10 is assigned to a, 20 is assigned to b and 30 is assigned to c. ... The second way ...
๐ŸŒ
Python Course
python-course.eu โ€บ python-tutorial โ€บ passing-arguments.php
25. Passing Arguments | Python Tutorial | python-course.eu
November 8, 2023 - Correctly speaking, Python uses a mechanism, which is known as "Call-by-Object", sometimes also called "Call by Object Reference" or "Call by Sharing". If you pass immutable arguments like integers, strings or tuples to a function, the passing acts like call-by-value.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ controlflow.html
4. More Control Flow Tools โ€” Python 3.14.3 documentation
The actual parameters (arguments) ... function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object)....
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_functions.asp
Python Functions
Python If Python Elif Python Else Shorthand If Logical Operators Nested If Pass Statement Code Challenge Python Match ... Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range
๐ŸŒ
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.
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ pass-assignment-python-what-you-need-know-shrawan-baral
Pass by Assignment in Python: What you need to know
June 20, 2023 - In Python, arguments to a function are passed by assignment. This means that when you call a function, each argument is assigned to a variable in the function's scope.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ typing.html
typing โ€” Support for type hints
1 month ago - Using -> TypeIs[NarrowedType] tells the static type checker that for a given function: The return value is a boolean. If the return value is True, the type of its argument is the intersection of the argumentโ€™s original type and NarrowedType. If the return value is False, the type of its argument is narrowed to exclude NarrowedType. ... from typing import assert_type, final, TypeIs class Parent: pass class Child(Parent): pass @final class Unrelated: pass def is_parent(val: object) -> TypeIs[Parent]: return isinstance(val, Parent) def run(arg: Child | Unrelated): if is_parent(arg): # Type of ``arg`` is narrowed to the intersection # of ``Parent`` and ``Child``, which is equivalent to # ``Child``. assert_type(arg, Child) else: # Type of ``arg`` is narrowed to exclude ``Parent``, # so only ``Unrelated`` is left.