重要内置函数

filter()

str = ['a','b','c','d']

def fun1(s):
if s != 'a':
return s

ret = filter(fun1,str)

print(list(ret))



map():
    str = ['a','b','c','d']

def fun2(s):
return s + "alvin"
ret = map(fun2,str)
print(list(ret))


reduce()
    from functools import reduce

def add1(x,y):
return x + y
print(reduce(add1,range(1,10))) #reduce()的结果就是一个值


lambda()
    def add(a,b):
return a+b

lambda a,b:a + b






posted @ 2019-07-08 10:59  python小白丶  阅读(121)  评论(0)    收藏  举报