Python函数(五)-高阶函数

函数接收的参数可以是数字,字符串,列表,元组,字典,集合,也可以是另一个函数,那么这个接收一个函数作为参数的函数就称为高阶函数

# -*- coding:utf-8 -*-
__author__ = "MuT6 Sch01aR"

def Calculate(n):
    n = n+1
    return n

def Main(a,b,c):
    d = c(a) +c(b)
    print(d)

Main(2,3,Calculate)

运行结果

还有一种是返回值中包含函数名

# -*- coding:utf-8 -*-
__author__ = "MuT6 Sch01aR"

def test1():
    print('in the test1')

def test2():
    print('in the test2')
    return test1

print(test2()) #打印test2()返回的值
test2()() #调用test2(),然后调用test2()的返回值,即执行test1(),test2()=test1,test2()()=test1()

运行结果

 

posted @ 2018-01-31 22:55  Sch01aR#  阅读(148)  评论(0编辑  收藏  举报