Python3 练习笔记七

# lambda
'''
lambda:
    定义:匿名函数关键字
    作用:减少单行函数的定义,提升代码的简洁程度
'''
gf = lambda x: x + 1
print(gf(3))
print(gf(0))

foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]
f = filter(lambda x: x % 3 == 0, foo)
for i in f:
    print(i)

m = map(lambda x: x * 2 + 10, foo)
for i in m:
    print(i)

 参考:https://www.cnblogs.com/PastimeRr/p/8305022.html

posted @ 2019-02-15 15:58  因为专注。所以专业  阅读(115)  评论(0编辑  收藏  举报