Discuss / Python / "Undefined variable 'reduce' 函数不存在

"Undefined variable 'reduce' 函数不存在

Topic source

使用 reduce() 测试的时候报错:reduce 未定义!

解决

引用stackoverflow的回答: 

- 你使用的是python3 

- 参考的是python2的指南

from functools import reduce  # py3

print(reduce(lambda x, y: x + y, [ 1, 2, 3]))


  • 1

Reply