Assigning a variable name to a function

In Python, functions are "first class'' objects: they can have variable names assigned to them, they can be passed as arguments to other functions, and can even be returned from other functions. A function is given a name when it is defined, but that name can be reassigned to refer a different object if desired (don't do this unless you mean to!)

As the following example demonstrates, it is possible for more than one variable name to be assigned to the same function object.

>>> def cosec(x):
...    """Return the cosecant of x, cosec(x) = 1/sin(x)."""
...    return 1./math.sin(x)
...
>>> cosec
<function cosec at 0x100375170>
>>> cosec(math.pi/4)
1.4142135623730951
>>> csc = cosec
>>> csc
<function cosec at 0x100375170>
>>> csc(math.pi/4)
1.4142135623730951

The assignment csc = cosec associates the identifier (variable name) csc with the same function object as the identifier cosec: this function can then be called with csc() as well as with cosec().