map函数的功能是根据提供的函数对指定序列做映射,就是对第二个参数的每一个值运行第一个参数所指定的函数
lambda是定义一个匿名函数
[crsusr@rws1270149 python_study]$ cat mypy02.py
#!/usr/bin/python3.7
#import sys,string,os
#from os import *
def square(x):
return x ** 2
result = list(map(square,(1,2,3,4)))
print (result)
result = list(map(lambda x:x + 8,(1,2,3,4)))
print(result)
result = list(map(lambda x,y:x + y,(1,2,3,4),(5,6,7,8)))
print(result)
[crsusr@rws1270149 python_study]$ ./mypy02.py
[1, 4, 9, 16]
[9, 10, 11, 12]
[6, 8, 10, 12]
参考了https://www.runoob.com/python/python-func-map.html