为了账号安全,请及时绑定邮箱和手机立即绑定

error:'int' object is not callable

def calc_prod(lst):
    def prod(x,y):
        return x * y
    return reduce(prod,lst)

f = calc_prod([1, 2, 3, 4])
print f()

为什么会报'int' object is not callable的错误。


正在回答

2 回答

calc_prod([1, 2, 3, 4]) 返回值是int而不是函数,所以你不能使用f()进行调用了

2 回复 有任何疑惑可以回复我~
def calc_prod(lst):
    def prod(x,y):
        return x * y
    def f():
        return reduce(prod,lst)
    return f
 
f = calc_prod([1, 2, 3, 4])
print f()

修改为上述才可以

2 回复 有任何疑惑可以回复我~
#1

慕慕5442811 提问者

原来如此!非常感谢
2017-09-14 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
python进阶
  • 参与学习       255533    人
  • 解答问题       3038    个

学习函数式、模块和面向对象编程,掌握Python高级程序设计

进入课程

error:'int' object is not callable

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号