lambda

优点:

1:可以简单使用一个脚本来替代我们的函数

2:不用考虑命名的问题

3:简化代码的可读性,不用跳转到def了,省去这样的步骤

 

内置函数:bif

filter:过滤器

map:映射

 1 >>> lambda x: 2*x+1 2 <function <lambda> at 0x00000000026C6AC8> 3 >>> g=lambda x: 2*x+1 4 >>> g(3) 5 7 6 >>> help(filter) 7 Help on built-in function filter in module __builtin__: 8  9 filter(...)10     filter(function or None, sequence) -> list, tuple, or string11     12     Return those items of sequence for which function(item) is true.  If13     function is None, return the items that are true.  If sequence is a tuple14     or string, return the same type, else return a list.15 16 >>> filter(None,[1,0,True,False])17 [1, True]18 >>> 
19 >>> 
20 >>> tmp=range(10)21 >>> tmp22 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]23 >>> def fun(x):24     return x%225 26 >>> filter(fun,tmp)27 [1, 3, 5, 7, 9]28 >>> list(filter(lambda x:x%2,range(10)))29 [1, 3, 5, 7, 9]30 >>> list(map(lambda x:x*2,range(10)))31 [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]32 >>>

 

 

 

递归

python限制的递归深度大概几百层,但是可以手动设置

》》》import sys

>>> sys.setrecursionlimit(10000)

python---------------------------------------eg'1------------------