1
def asterisk_test(c, b, *args):
  a + b + sum(args)
  
print(asterisk_test(1,2,3,4,5))

它使错误称为

TypeError: 'NoneType' object is not callable

所以我尝试将元组更改为列表

def asterisk_test(c, b, *args):
  a + b + sum(list(args))
  
print(asterisk_test(1,2,3,4,5))

但它会发出相同的错误消息。

为什么python将元组类型识别为“Nonetype”?

4

1 回答 1

0

我会假设你已经sum在你的代码中分配了一些东西。我在下面提供的代码代表了这一点。虽然sum可能不会直接分配给None.

sum = None
def asterisk_test(c, b, *args):
    print(c+b+sum(args))
  
print(asterisk_test(1,2,3,4,5))

所以如果我们尝试上面的代码,我们会得到TypeError: 'NoneType' object is not callable,因为 python 认为我们在做None(args). 所以我建议你做的是查看你的代码并搜索你定义的任何时间sum。更改该变量名称,不要使用诸如tuples, list, sumetc之类的名称。

于 2021-05-13T02:13:53.327 回答