Let's define a simple function
def f(n):
return n + 5
We can now do the following:
g = f
This means that the variables g and f now refer to the same function. That means we can go:
g(10)
Here is a generalization of this idea:
def applyit(func, arg):
'''Return the value of func(arg)
Arguments:
func -- a function
arg -- an object
'''
return func(arg)
applyit(f, 10)
What happens is that f gets assigned to the local variable func, and 10 gets assigned to the local variable arg. We then obtain 15, as before.