Python, assign function to variable, change optional argument's value
Question: Is it possible to assign a function to a variable with modified default
arguments?

To make it more concrete, I'll give an example. The following obviously
doesn't work in the current form and is only meant to show what I need:

    
    
    def power(a, pow=2):
        ret = 1
        for _ in range(pow):
            ret *= a
        return ret
    
    cube = power(pow=3)
    

And the result of `cube(5)` should be `125`.


Answer: [`functools.partial`](https://docs.python.org/2/library/functools.html#functools.partial)
to the rescue:

> Return a new partial object which when called will behave like func called
> with the positional arguments args and keyword arguments keywords. If more
> arguments are supplied to the call, they are appended to args. If additional
> keyword arguments are supplied, they extend and override keywords.
    
    
    from functools import partial
    
    cube = partial(power, pow=3)
    

Demo:

    
    
    >>> from functools import partial
    >>> 
    >>> def power(a, pow=2):
    ...     ret = 1
    ...     for _ in range(pow):
    ...         ret *= a
    ...     return ret
    ... 
    >>> cube = partial(power, pow=3)
    >>> 
    >>> cube(5)
    125
    

