肉松君

在sololearn上做练习,不小心接触到了高阶函数
中文叫函数式编程,乍一看这题直接懵逼了,函数作为变量代入另一个函数 直接看晕了,最后我理解的是,如果一个函数变量是...
扫描右侧二维码阅读全文
06
2018/06

在sololearn上做练习,不小心接触到了高阶函数

中文叫函数式编程,乍一看这题直接懵逼了,函数作为变量代入另一个函数
直接看晕了,最后我理解的是,如果一个函数变量是另一个函数的话,那么这个函数就是高阶函数(higher-order functions
实际上要传达的一个最重要的观念就是函数本身也可以作为变量被返回、传递给高阶函数

Functional programming is a style of programming that (as the name suggests) is based around functions.
A key part of functional programming is higher-order functions
We have seen this idea briefly in the previous lesson on functions as objects.
Higher-order functions take other functions as arguments, or return them as results.

[sourcecode language="python"]
def test(func, arg):
return func(func(arg))

def mult(x):
return x * x

print(test(mult, 2))
[/sourcecode]

Last modification:September 12th, 2018 at 08:51 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment