码迷,mamicode.com
首页 > 编程语言 > 详细

十、python沉淀之路--高阶函数初识

时间:2018-04-28 01:20:52      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:--   bsp   测试   地球   ret   test   一个   turn   class   

一、高阶函数:分两种:一种是返回值中包含函数体;另一种是把一个函数体当作了参数传给了另一个函数

1、返回值中包含函数体

例1、

1 def test():
2     print(这是一个测试)
3     return test
4 
5 f = test()
6 f()
1 这是一个测试
2 这是一个测试

例2

1 def inward():
2     print(from inward)
3 def outward():
4     print(from outward)
5     return inward
6 
7 f = outward()
8 f()
1 from outward
2 from inward

2、把一个函数体当作一个参数传给另一个函数

例1

1 def inward(name):
2     print(%s is from inward %name)
3 
4 def outward(n):
5     print(我来自地球以外)
6 
7 outward(inward())
1is from inward
2 我来自地球以外

 

十、python沉淀之路--高阶函数初识

标签:--   bsp   测试   地球   ret   test   一个   turn   class   

原文地址:https://www.cnblogs.com/jianguo221/p/8965110.html

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