代码改变世界

Python 匿名函数

2018-04-20 19:15  钱先生  阅读(148)  评论(0编辑  收藏  举报

匿名函数

 1 def calc(n):
 2     return n**n
 3 
 4 
 5 print(calc())
 6 
 7 
 8 # 换成匿名函数
 9 calc = lambda n:n**n
10 print(calc(n))
11 
12 
13 # 匿名函数主要是搭配其它函数使用
14 res = wap(lambda x:x**2,[1,5,7,4,8])
15 for i in res:
16     print(i)