python自带函数map,python3与python2下的用法区别

本文介绍了Python内置函数map的用法,对比了Python3和Python2中map函数的区别。在Python3中,map返回一个map对象,需通过list转换或for循环访问结果;而在Python2中,map直接返回结果列表。此外,当map函数为None时,两者的处理方式也有所不同。
摘要由CSDN通过智能技术生成

1、首先简要介绍下map函数的用法

      都是针对参数,逐个作用到函数上,Python3得到的结果是map 对象;Python2得到的对象是list

(1)Python3

  map(func, *iterables) --> map object

Make an iterator that computes the function using arguments from
each of the iterables.  Stops when the shortest iterable is exhausted.

(2)Python2

map(function, sequence[, sequence, ...]) -> list

    Return a list of the results of applying the function to the items of
    the argument sequence(s).  If more than one sequence is given, the
    function is called with an argument list consisting of the corresponding
    item of each sequence, substituting None for missing values when not all
    sequences have the same length.  If the function is None, return a list of
    the items of the sequence (or a list of tuples if more than one sequence).

2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值