In Python, functions are objects too

In [1]:
# - compatibility with Python 3
from __future__ import print_function  # print('me') instead of print 'me'
from __future__ import division  # 1/2 == 0.5, not 0

If I make a string in Python:

In [2]:
name = 'Matthew'

then I have a Python object of type str:

In [3]:
type(name)
Out[3]:
str

Let's say I defined a function add:

In [4]:
def add(a, b):
    return a + b

Now I have another Python object, of type function:

In [5]:
type(add)
Out[5]:
function

With my string, I can refer to the same string object, with a different variable name:

In [6]:
prisoner = name
prisoner
Out[6]:
'Matthew'

It's the same for functions, because they are objects too:

In [7]:
my_add = add
type(my_add)
Out[7]:
function

Functions are objects you can "call" by following the function object name with parentheses and arguments you want to pass:

In [8]:
add(1, 2)
Out[8]:
3
In [9]:
my_add(1, 2)
Out[9]:
3

As for any other object in Python, you can pass function objects to other functions:

In [10]:
def run_a_func(func, arg1, arg2):
    result = func(arg1, arg2)
    print('Result was', result)
In [11]:
run_a_func(add, 1, 2)
Result was 3
In [12]:
run_a_func(my_add, 1, 2)
Result was 3
In [13]:
def sub(a, b):
    return a - b
In [14]:
run_a_func(sub, 1, 2)
Result was -1