转载:https://www.cnblogs.com/newt/p/8997586.html

编程的方法论:

  面向过程

  面向对象

  函数式

 

函数式编程的定义:

  函数式=编程语言定义的函数+数学意义上的函数(先想到一个数学模型,再用python上的功能实现这个逻辑)

y = x + 1

def cat():
    return x + 1

 

特性:

1.不用变量保存状态,意思就是不赋值,而且不修改变量

2.第一类对象:函数即变量

#高阶函数1。函数接收的参数是一个函数名  2#返回值中包含函数
# 把函数当作参数传给另外一个函数
# def foo(n): 
#     print(n)
#
# def bar(name):
#     print('my name is %s' %name)
#
# # foo(bar)
# # foo(bar())
# foo(bar('ray'))

#返回值中包含函数
def bar():
    print('from bar')
def foo():
    print('from foo')
    return bar
n=foo()
n()
def hanle():
    print('from handle')
    return hanle
h=hanle()
h()



def test1():
    print('from test1')
def test2():
    print('from handle')
    return test1()
posted on 2019-10-25 10:19  月零Ray  阅读(132)  评论(0编辑  收藏  举报