且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

串联Python列表时出现问题

更新时间:2022-02-06 21:14:35

使用+运算符

>>> [6] + [1,1,0,0,0]
[6, 1, 1, 0, 0, 0]

您尝试执行的操作是将一个列表追加到另一个列表中,这将导致

What you were attempting to do, is append a list onto another list, which would result in

>>> [6].append([1,1,0,0,0])
[6, [1,1,0,0,0]]

为什么看到None返回,是因为.append具有破坏性,修改了原始列表并返回了None.它不会返回您要附加的列表.因此,您的列表 已被修改,但是您正在打印函数.append的输出.

Why you are seeing None returned, is because .append is destructive, modifying the original list, and returning None. It does not return the list that you're appending to. So your list is being modified, but you're printing the output of the function .append.