对python函数后面有多个括号的理解

一般而言,函数后面只有一个括号。如果看见括号后还有一个括号,说明第一个函数返回了一个函数,如果后面还有括号,说明前面那个也返回了一个函数。以此类推。

比如fun()()

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 as

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

在学习过程中有什么不懂得可以加我的
python学习扣扣qun,784758214
群里有不错的学习视频教程、开发工具与电子书籍。
与你分享python企业当下人才需求及怎么从零基础学习好python,和学习什么内容

def fun81(functions):
    def f(x):
        for fun in functions:
            x = fun(x);
        return x;
    return f;
发布了62 篇原创文章 · 获赞 3 · 访问量 1320

猜你喜欢

转载自blog.csdn.net/NNNJ9355/article/details/103931231