python中map()的用法

本文环境是python3

代码格式:map(func,Iterable) 

功能:把Iterable里面的数据拿出来,一个一个的传到func函数中进行运算,把运算好的值,直接仍给迭代器,最终返回迭代对象

参数::func 自定义函数 或 内置函数       Iterable:可迭代对象(容器类型数据,range对象,迭代器)

返回值:迭代对象

1 lst=[1,2,3,4]
2 s=map(lambda x : x**2,lst)
3 print(s) # PY2中返回列表,py3返回迭代对象
4 print("返回map的对象类型",type(s))
5 print("序列化输出",list(s))
原文地址:https://www.cnblogs.com/youhongliang/p/12230547.html