课程
/后端开发
/Python
/python进阶
提示 Undefined variable 'reduce'
2019-01-04
源自:python进阶 2-5
正在回答
引入from functools import reduce
这句话就行了,直接复制过去,放在最上边一行
python3.x版本后没有reduce()函数了,如果想用还是可以的,详细步骤见:
http://www.runoob.com/note/26811
import functools def add_sum(x,y): return x+y x = functools.reduce(add_sum,[1],100) print (x)
舞台中的鱼
https://stackoverflow.com/questions/13638898/how-to-use-filter-map-and-reduce-in-python-3
python3中用functools.reduce
你的把代码贴出来
这样没头没尾,没办法判断
举报
学习函数式、模块和面向对象编程,掌握Python高级程序设计
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号