Python Forum

Full Version: function as parameter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
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
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