python编程遇见的坑

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lionel_fengj/article/details/82871258
  • python2和python3中的map 函数
    def square(x):
    	return x**2
     map(squre, [1,2,3,4,5])
    
    分别在 python2和 python3环境执行以上代码,执行结果如下
    python2: [1, 4, 9, 16, 25]
    python3: <map object at 0x101e9b710>
    
    如果想要在 python3环境看具体内容,需要使用list(map(square, [1,2,3,4,5]))

猜你喜欢

转载自blog.csdn.net/lionel_fengj/article/details/82871258