py-day3-5 python 函数式编程

# 函数式(方程式 y = 2*x+1)
def calc(x):
    return 2*x+1
print('得出的结果:',calc(6))

得出的结果: 13

# 面向过程
def calc(x):
    res = 2*x
    res +=1
    return res
print('得出的结果是:',calc(6))

得出的结果是: 13
高阶函数---------------------------------------
#
把函数当作参数传给另一个函数 def foo(n): print(n) def bar(name): print('my name is %s'%name) foo(bar('xiaoma')) my name is xiaoma None
# 返回值中包含函数
def bar():
    print('from bar')
def foo():
    print('from foo')
    return bar
n = foo()
n()

from foo
from bar
# 返回带执行的函数 就是有()的
def test1():
    print('from test1')
def test2():
    print('from test2')
    return test1()
n = test2()

from test2
from test1
原文地址:https://www.cnblogs.com/majunBK/p/10432295.html