-2

Given numbers [1,2,3,4} if I appended 4 what would the list now be?

Given the same list of numbers if I inserted 4 what would the result be.

Im new in programming (dont roast me lol) and am not grasping this concept yet.

Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
Trip
  • 1

1 Answers1

0

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]

Daniel Hao
  • 4,922
  • 3
  • 10
  • 23