L21匿名函數lambda()
2016-03-18 15:52
351 查看
lambda(參數:返回值) >>> def ds(x): return 2*x+1
>>> ds(5) 11 >>> lambda x : 2*x+5 <function <lambda> at 0x02C66D68> >>> g = lambda x : 2*x+5 >>> g(5) 15 #兩個參數 >>> def add(x,y): return x + y >>> add(3,4) 7 >>> >>> lambda x,y : x + y <function <lambda> at 0x02EEA078> >>> g = lambda x,y : x + y >>> g(3 , 7) 10 #filter(function, iterable) #過濾器:把任何非true的內容過濾掉 >>> filter(None,[1, 0, False, True]) <filter object at 0x02C8D910>
>>> list(filter(None,[1, 0, False, True])) [1, True] --------------------------------------------------------------- >>> def odd(x): x = x%2 return x >>> temp = range(10) >>> show = filter(odd,temp) >>> list(show) [1, 3, 5, 7, 9] >>> list(filter(lambda x:x%2, range(10))) [1, 3, 5, 7, 9] #因為偶數的話餘0>>>False ----------------------------------------------------------------- #map()映射:將序列的函數作為每一個函數加工 >>> list(map(lambda x:x*2, range(10))) [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
相关文章推荐
- Python:鼠标滑动时坐标变化显示
- Python学习笔记--装饰器
- Java中使用Jedis操作Redis
- mysql有用的函数集锦
- 初识F5之BIGIP-LTM负载均衡
- JavaScript中判断对象是否存在的若干方法
- java工程师最新面试题(java语言基础)
- CentOS SELinux
- 关于ListView 下标混乱的处理
- [Java代码] [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度
- 基于 CMMI 的软件外包管理评估体系
- struct 字节对齐详解与大小端模式
- 获取字的高度和宽度
- 区别 __cdecl,__fastcall,__stdcall,thiscall
- Android 事件分发机制
- 一行 Python 实现并行化 -- 日常多线程操作的新思路
- Module
- 创建windows新用户的时候如何删除原来的用户
- 命令行界面(CLI)CommandLine Interface
- spring之依赖注入