您的位置:首页 > 编程语言 > Python开发

map函数

2015-08-30 23:36 1221 查看
"""
1、map函数:对序列对象中的每一个元素应用被传入的函数,并且返回一个
包含了所有函数调用结果的一个列表
"""

def inc(x):
return x+10

counts = [1,2,3,4]
"""
输出结果:
<type 'list'>
[11, 12, 13, 14]
"""
print type(map(inc,counts))
print map(inc,counts)

"""
2、map函数同lambda表达式同时使用
"""
print map((lambda x:x+10),counts)  #上面的lambda实现

"""
3、map函数接收多个序列参数的情况,要求一个个函数参数对应有
同样个数的参数
"""
"""
输出结果:
[1, 4, 27]
"""
print map(pow,[1,2,3],[1,2,3]) #Pow(x,y),x**y
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python map