我试图了解内置sum()
函数的工作原理,但是,这个start
参数已经让我忘记了:
a=[[1, 20], [2, 3]] b=[[[[[[1], 2], 3], 4], 5], 6] >>> sum(b,a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "int") to list >>> sum(a,b) [[[[[[1], 2], 3], 4], 5], 6, 1, 20, 2, 3]
>>> a=[1,2] >>> b=[3,4] >>> sum(a,b) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "int") to list >>> sum(b,a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "int") to list
我对此感到目瞪口呆,不知道发生了什么。这是 python 文档必须说的: http: //docs.python.org/library/functions.html#sum。这没有对“如果开始不是字符串而不是整数怎么办?”给出任何解释。