python3中输出map的问题

来源:互联网 发布:官方mac os 10.9.5 编辑:程序博客网 时间:2024/05/21 08:44
def toUpper(item):    return item.upper()upper_name = map(toUpper, ["hao", "chen", "coolshell"])print(upper_name)#print(list(upper_name))# 输出 ['HAO', 'CHEN', 'COOLSHELL']

在python2中会输出: [‘HAO’, ‘CHEN’, ‘COOLSHELL’]
在python3中会输出类似:的内容,而不是想要的输出
原因是python2中map函数会返回一个list列表,而python3中不会。
解决办法是添加一个类型转换list(),把map转换为list类型。

原创粉丝点击