码迷,mamicode.com
首页 > 其他好文 > 详细

高阶函数

时间:2019-09-12 23:12:31      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:匿名   func   开始   结束   一起   fun   函数   int   turn   

# 函数的参数是一个函数或函数的返回值是一个函数,称这样的函数称为高阶函数
def show(new_func):
print(‘show函数执行了!‘)
new_func(‘调用参数函数‘)
print(‘show函数结束‘)
# 高阶函数结合匿名函数一起使用
show(lambda mes:print(mes))


# 高阶函数,返回值还是一个函数
def show2():
print(‘外部函数开始执行了‘)
def inner():
print(‘内部函数执行了‘)
return inner #返回的是一个函数,但是不能加括号

# result = show2()
# print(result,type(result)) #返回值还是一个函数,调用要加括号
# result()

show2()() #还可以这样调用

高阶函数

标签:匿名   func   开始   结束   一起   fun   函数   int   turn   

原文地址:https://www.cnblogs.com/wjun0/p/11515384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!