5.16 functional -- Higher order functions and operations on callable objects.

New in version 2.5.

The functional module is for higher-order functions: functions that act on or return other functions. In general, any callable object can be treated as a function for the purposes of this module.

The functional module defines the following function:

partial( func[,*args][, **keywords])
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. Roughly equivalent to:
        def partial(func, *args, **keywords):
            def newfunc(*fargs, **fkeywords):
                newkeywords = keywords.copy()
                newkeywords.update(fkeywords)
                return func(*(args + fargs), **newkeywords)
            newfunc.func = func
            newfunc.args = args
            newfunc.keywords = keywords
            return newfunc

The partial is used for partial function application which ``freezes'' some portion of a function's arguments and/or keywords resulting in a new object with a simplified signature. For example, partial can be used to create a callable that behaves like the int function where the base argument defaults to two:

        >>> basetwo = partial(int, base=2)
        >>> basetwo.__doc__('Convert base 2 string to an int.')
        >>> basetwo('10010')
        18



Subsections
See About this document... for information on suggesting changes.