Terms explained: append
is putting the new item
at the tail/end of an existing list/array. And insert
is to put the new
item at specific position or index
. There are more info. you can read through to deepen your understanding here - https://docs.python.org/3/tutorial/datastructures.html
Let's have some examples to show the difference:
lst = [1, 2, 3, 4, 5]
x = 9
lst.append(x) # lst becomes - [1, 2, 3, 4, 5, 9]
y = 11
lst.insert(3, y) # lst now is - [1, 2, 3, 11, 4, 5, 9]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…