一般而言,函數后面只有一個括號。如果看見括號后還有一個括號,說明第一個函數返回了一個函數,如果后面還有括號,說明前面那個也返回了一個函數。以此類推。
比如fun()()
def fun():
print("this is fun");
def _fun():
print("this is _fun");
return _fun;
PS:遇到問題沒人解答?需要Python學習資料?可以加點擊下方鏈接自行獲取
note.youdao.com/noteshare?id=2dce86d0c2588ae7c0a88bee34324d76
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中也可以鏈式點用函數,只是函數需要在返回一個函數。