I am trying to store a function as a variable and pass parameters to the function through the variable. So for example, consider this:
def the_funct(*args):
the_sum = 0
for arg in args:
the_sum += arg
return the_sum
If I set the function like this:
the_var = the_funct()
And then try to call it like this:
print('the var: ' + str(the_var(5)))
print('***********')
It throws a type error like this:
TypeError: 'int' object is not callable
If I do this:
print('the var: ' + str(the_var))
print('***********')
It evaluates.
So I think I'm missing something fundamental about passing parameters into functions that are stored as variables...any ideas for what it might be? Other threads I've read suggest the above should work.
the_varis not a function, so why are you calling it?the_var = the_funct()You asked python to "run"/call the function, and then assigned only the return of it. Note the brackets afterthe_funct(). If you want to assign the function, don't call the function, leave the brackets out.