python中的map()函数详解

map()函数

    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.

有道翻译结果:
”“”
map(func, *iterables)——> map对象

创建一个迭代器,使用来自的参数计算函数
每个迭代器。当最短的迭代器耗尽时停止。
”“”

作用
返回一个迭代器,对iterable的每个项应用function,生成结果。

因为返回值是一个迭代器所以直接打印map()的结果会出现这样的<map object at 0x00000112F878BE80>这是一个map对象

想要输出结果接着往下看

使用for循环遍历输出

num = ['1', '2', '3']
nums = map(lambda x:int(x),num)
for i in nums:
    print(i,end=" ")

输出结果为:1 2 3

使用list()转列表输出

num = ['1', '2', '3']
print(list(map(lambda x: int(x), num)))
···
输出结果为:

[1, 2, 3]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值