Pychram中使用reduce()函数报错:Unresolved reference 'reduce'

python3不能直接使用reduce()函数,因为reduce() 函数已经被从全局名字空间里移除了,它现在被放置在fucntools 模块里,所以要使用reduce函数得先饮用fucntools

例如:

>>> from functools import reduce

>>> reduce(lambda x,y:x+y,[1,2,3,4,5])

15

猜你喜欢

转载自www.cnblogs.com/HuangXiaoJuan/p/10857616.html
今日推荐