python中若是函数后面有多于一个括号是怎么回事?

通常而言,调用一个函数是加一个括号。若是看见括号后还有一个括号,说明第一个函数返回了一个函数,若是后面还有括号,说明前面那个也返回了一个函数。以此类推。html

好比fun()()python

def fun():
    print("this is fun");
    def _fun():
        print("this is _fun");
    return _fun;

Your task is to write a higher order function for chaining together a list of unary functions. In other words, it should return a function that does a left fold on the given functions.
chained([a,b,c,d])(input)函数

Should yield the same result aspost

d(c(b(a(input))))this

def fun81(functions):
    def f(x):
        for fun in functions:
            x = fun(x);
        return x;
    return f;

小结:python中也能够链式点用函数,只是函数须要在返回一个函数。spa

转载于:https://www.cnblogs.com/zhaopengcheng/p/5492481.htmlcode