问题描述
给定数字 [1,2,3,4},如果我附加 4,现在列表会是什么?
给定相同的数字列表,如果我插入 4,结果会是什么。
我是编程新手(不要烤我哈哈),我还没有掌握这个概念。
解决方法
条款解释:append
将 new item
放在现有列表/数组的尾部/末尾。而 insert
是将 new
项放在特定位置或 index
。还有更多信息。您可以在这里通读以加深理解 - https://docs.python.org/3/tutorial/datastructures.html
让我们举一些例子来说明区别:
lst = [1,2,3,4,5]
x = 9
lst.append(x) # lst becomes - [1,5,9]
y = 11
lst.insert(3,y) # lst now is - [1,11,9]