问答详情
源自:2-5 python中reduce()函数

在python里面找不到函数

>>> def f(x,y): return x+y >>> reduce(f,[1,3,5,7,9],100) Traceback (most recent call last):  File "

", line 1, inreduce(f,[1,3,5,7,9],100) NameError: name 'reduce' is not defined 为什么在python里面找不到函数#3>

提问者:慕尼黑0262996 2018-01-18 12:55

个回答

  • Rocol
    2018-01-18 13:50:46
    已采纳

    同学你使用的是Python3吧!在Python 3里,reduce()函数已经被从全局名字空间里移除了,它现在被放置在fucntools模块里。用的话要 先引入from functools import reduce