OneBite.Dev - Coding blog in a bite size

insert an element at the end of an array in python

Code snippet on how to insert an element at the end of an array in python

  arr = [1, 2, 3]
  arr.append(4)

This code appends an element to the end of an array. The array is first initialized as a list of integers, [1, 2, 3]. Then the built-in append() function is used to add the value 4 to the end of the array. The append() function takes one parameter, which is the object to add to the array, in this case the integer 4. The result is that the array arr becomes [1, 2, 3, 4].

python