python3中解决调用map()函数出现map object at 0x01690DF0问题

python3中运行以下程序,报错<map object at 0x01690DF0>

list_1=[1,2,3,4,5,6]
def double_func(x):
    return(x*2)
list_2=map(double_func,list_1)
print(list_2)

原因:python3中map()返回iterators类型,不再是list类型。进行list转换即可

list_1=[1,2,3,4,5,6]
def double_func(x):
    return(x*2)
list_2=map(double_func,list_1)
print(list(list_2))

运行结果为 [2, 4, 6, 8, 10, 12]

猜你喜欢

转载自blog.csdn.net/rain699/article/details/87901639