前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python文档精要研读系列(1):map函数

Python文档精要研读系列(1):map函数

作者头像
Python中文社区
发布2018-01-31 12:31:07
6260
发布2018-01-31 12:31:07
举报
文章被收录于专栏:Python中文社区Python中文社区

map(function, iterable, ...)

Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with None items. If function is None, the identity function is assumed; if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose operation). The iterable arguments may be a sequence or any iterable object; the result is always a list.

对可迭代函数'iterable'中的每一个元素应用‘function’方法,将结果作为list返回。python中的map函数应用于每一个可迭代的项,返回的是一个结果list。如果有其他的可迭代参数传进来,map函数则会把每一个参数都以相应的处理函数进行迭代处理。map()函数接收两个参数,一个是函数,一个是序列,map将传入的函数依次作用到序列的每个元素,并把结果作为新的list返回。

实例:

对hh中的元素做了add100,返回了结果的list:

如果给出了额外的可迭代参数,则对每个可迭代参数中的元素‘并行’的应用‘function’:

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2016-10-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Python中文社区 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档