zoukankan      html  css  js  c++  java
  • 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))))

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

    小结:python中也可以链式点用函数,只是函数需要在返回一个函数。

  • 相关阅读:
    身份证的测试用例
    集合
    网易考拉测试面试题整理
    linux基本指令分类
    网络编程
    设计模式
    MySQL中的索引
    MySQL中的事务
    Java判断字符串是否为乱码
    Activiti6.x删除外键
  • 原文地址:https://www.cnblogs.com/zhaopengcheng/p/5492481.html
Copyright © 2011-2022 走看看