教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 python中map什么意思

python中map什么意思

发布时间:2020-11-16   编辑:jiaochengji.com
教程集为您提供python中map什么意思等资源,欢迎您收藏本站,我们将为您提供最新的python中map什么意思资源

python中map什么意思?

python中map() 会根据提供的函数对指定序列做映射。

第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。

语法

map() 函数语法:

map(function, iterable, ...)

参数

function -- 函数

iterable -- 一个或多个序列

返回值

Python 2.x 返回列表。

Python 3.x 返回迭代器。

以下实例展示了 map() 的使用方法:

>>>def square(x) :            # 计算平方数
...     return x ** 2
... 
>>> map(square, [1,2,3,4,5])   # 计算列表各个元素的平方
[1, 4, 9, 16, 25]
>>> map(lambda x: x ** 2, [1, 2, 3, 4, 5])  # 使用 lambda 匿名函数
[1, 4, 9, 16, 25]
 
# 提供了两个列表,对相同位置的列表数据进行相加
>>> map(lambda x, y: x   y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10])
[3, 7, 11, 15, 19]

相关推荐:《Python教程》

以上就是python中map什么意思的详细内容,更多请关注教程集其它相关文章!

  • 本文原创发布教程集,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    python中map什么意思
    map在python中什么意思
    golang 并发访问map遇到的问题
    python中的%是什么意思
    python中的map怎么使用(方法详解)
    python中r代表什么意思
    python中转义字符是什么意思
    python中divmod是什么意思
    python中num是什么意思
    python中的def语句是什么意思

    [关闭]
    ~ ~