簡單瞭解為什麼python函式後有多個括號
阿新 • • 發佈:2020-01-09
這篇文章主要介紹了簡單瞭解為什麼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中也可以鏈式點用函式,只是函式需要在返回一個函式。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。