【发布时间】:2019-05-04 17:13:44
【问题描述】:
用例:
我想将一个新项目与列表中的所有现有项目一起附加到同一个列表中。
例如:
list = [ 'a', 'b', 'c']
附加'd',期望输出为:['a', 'b', 'c', 'a', 'b', 'c', 'd']
我的代码:
list.append(list.append('d'))
当前输出:
['a', 'b', 'c', 'd', None]
为什么我会在此处收到 None 项目,如何按预期打印列表?
【问题讨论】:
-
注意:应该避免隐藏像
list这样的内置名称。我建议使用不同的变量名。