更新时间:2022-11-11 13:31:50
追加
是一个破坏性操作(它会修改的地方,而不是返回一个新的列表清单) 。惯用的方式做的非破坏性相当于追加
是
append
is a destructive operation (it modifies the list in place instead of of returning a new list). The idiomatic way to do the non-destructive equivalent of append
would be
l = [1,2,3]
print l + [4] # [1,2,3,4]
print l # [1,2,3]
要回答你的问题,我的猜测是,如果追加
返回新修改的列表中,用户可能会认为这是无损的,即它们可以写$ C $ ç像
to answer your question, my guess is that if append
returned the newly modified list, users might think that it was non-destructive, ie they might write code like
m = l.append("a")
n = l.append("b")
和期望 N
是 [1,2,3,B]