Python程序生成TypeError:str对象不可调用

时间:2019-10-25 20:54:05

标签: python typeerror

当尝试打印以下结果时,在其中一行(第26行)中出现类型错误:

def myreduce(func, lst):
    x = 0
    x1 = x + 1
    result = lst[x]
    while x1 < len(lst):
        applyfunc = func(result, lst[x1]) #This is the line in question
        result = applyfunc
        x += 1
        x1 += 1
    return round(result, 1)

print(myreduce('`complex`', [3, -1, 4.5, 23, 10]))

2 个答案:

答案 0 :(得分:0)

您需要将一个函数作为第一个参数传递给OrTest函数。 您正在传递字符串。

答案 1 :(得分:0)

问题是您在哪里调用函数。 代替:

print(myreduce('`complex`', [3, -1, 4.5, 23, 10]))

您必须写:

print(myreduce(complex, [3, -1, 4.5, 23, 10]))
相关问题