Python:函数式编程与函数
2016-04-05 14:31
495 查看
1. lambda 单行函数
lambda允许用户快速定义单行函数,目的是简化用户定义使用函数的过程。func =lambda x: x *2 # 定义lambda函数,通过赋值给func进行调用 func(3) >>> 6
lambda参数列表可以包含多个参数,如
lambda x, y: x + y
2. map(func,seq1[,seq2])
将func作用于seq中的每个元素,并用一个列表的形式给出返回值3. 普通函数
3.1 函数的定义
def hello(name): return 'hello ' + name + '!' print hello('a') >>>hello a!
递归函数举例:
def foo(i): print 'the number is: ', i i+=1 if i<10: foo(i) else: print 'end!' foo(0)
结果为:
>>> the number is: 0 the number is: 1 the number is: 2 the number is: 3 the number is: 4 the number is: 5 the number is: 6 the number is: 7 the number is: 8 the number is: 9 end!
相关文章推荐
- python+selenium+scrapy搭建简单爬虫
- Python:类与结构体
- uva352 The Seasonal War-python
- python学习过程-集合和for循环
- 利用python下载网页到本地(python3)
- [LeetCode]题解(python):133-Clone Graph
- K近邻分类算法实现 in Python
- ArcMap中用python的split方法提取字段的值
- Python:random模块
- python小项目1
- python内建函数sorted方法概述
- python内建函数sorted方法概述
- Ilya and Escalator-python
- Python:正则表达式模块
- python进阶
- python路径相关的函数os.listdir(dirname):列出dirname下的目录和文件
- python os.path模块常用方法详解
- python实现并行爬虫
- python多线程threading
- python(7)– 类的反射