TypeError: can only concatenate list (not “int“) to list
代码:c = [1,2]a = [2,[7],6]b = [5,8]c.append(a)c.append(b)c = sum(c,[])print(c)以上代码本想将列表元素连接在一起,放在C中。但是报错:TypeErrorTraceback (most recent call last)<ipython-input-1-452d9434d5cd> in <module>
·
代码:
c = [1,2]
a = [2,[7],6]
b = [5,8]
c.append(a)
c.append(b)
c = sum(c,[])
print(c)
以上代码本想将列表元素连接在一起,放在C中。但是报错:
TypeError Traceback (most recent call last) <ipython-input-1-452d9434d5cd> in <module> 5 c.append(b) 6 ----> 7 c = sum(c,[]) 8 print(c) TypeError: can only concatenate list (not "int") to list
因为c里面原来的元素是int,现在将list a和list b和原来的元素一起拼接,报错。因此concatenate的元素必须是list
更多推荐
已为社区贡献1条内容
所有评论(0)