python map()函数
map()函数会根据提供的函数对指定序列做映射。
map()函数的语法
map(function, iterable,...)
参数说明
function --函数
iterable --一个或多个序列
>>> def square(x) : # 计算平方数 ... return x ** 2 ... >>> map(square, [1,2,3,4,5]) # 计算列表各个元素的平方
map()函数会根据提供的函数对指定序列做映射。
map()函数的语法
map(function, iterable,...)
参数说明
function --函数
iterable --一个或多个序列
>>> def square(x) : # 计算平方数 ... return x ** 2 ... >>> map(square, [1,2,3,4,5]) # 计算列表各个元素的平方