函数式编程简介
函数式编程的历史非常早,它的特点是执行简洁但可读性较差。
函数式编程中的函数=编程语言定义的函数+数学中的函数
Python不是严格意义上的函数式编程语言,函数式编程语言有:Hashell、clean、erlang
函数式编程的特点和例子
1.函数式编程不用变量保存状态,不修改变量。
#非函数式编程
a = 1
def test():
global a
a += 1
return a
print(test())
#函数式编程
def test():
return n + 1
print(test())
2.把函数当作参数传给另一个函数
def test1(x):
print(x)
def test2(name):
print("my name is %s" % name)
print(test1(test2("YY")))