摘要:
下文讲述Python代码中map()函数的功能说明,如下所示:
map()函数功能说明
map()函数功能:
用于使用参数中的函数对参数中的序列进行映射
map()函数语法:
map(function, iterable, ...)
-------参数说明----
function:函数
iterable:一个或多个序列
-------返回值说明----
Python2.X 返回列表
Python3.X 返回迭代器
例:
Python map修饰符示例分享
#maomao365.com
#map函数的示例分享
def funTest(x) : # 变大十倍
return x *10
t=map(funTest, [8,89,1,11,66]) #所有元素变大十倍
print(list(t))
t2=map(lambda x: x ** 2, [1, 2, 3, 4, 5]) # 使用 lambda 匿名函数
print(list(t2))
#当传入两个列表,对相同位置的列表数据进行相乘
#并返回新列表
t3=map(lambda x, y: x*y, [8, 1, 6, 4, 3], [10, 2, 5, 7, 9])
print(list(t3))
//输出
[80, 890, 10, 110, 660]
[1, 4, 9, 16, 25]
[80, 2, 30, 28, 27]
Python之map函数示例说明