Python Forum
function as parameter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: function as parameter (/thread-44192.html)



function as parameter - Azdaghost - Mar-29-2025

hello and i have a question about python

are you able to add a function as a parameter and still run it?

here's what it would look like:
def function_load(function):
    function() # parameter

def add(x, y):
    return x + y

print(function_load(add(x, y)))

# or...

# this in tkinter
#                 func
window.after(0, forever)



RE: function as parameter - buran - Mar-29-2025

Something like

def function_load(function, *params):
    return function(*params) # parameter
 
def add(x, y):
    return x + y

x = 3
y = 5
print(function_load(add, x, y))
there might be better approach, depending what exactly you want to achieve


RE: function as parameter - DeaD_EyE - Apr-01-2025

With First Class Functions In Python, you can:
  • assign functions to names
  • pass them along as arguments
  • store them in bigger data structures
  • define them inside another function and also return them from another function just like any other objects