OneBite.Dev - Coding blog in a bite size

append item in array in python

Code snippet on how to append item in array in python

  my_arr = ['apple', 'banana','mango']
  my_arr.append('pineapple')

This code will add an item to array in Python. First, we define an array named my_arr with three items - ‘apple’, ‘banana’, and ‘mango’. Then, we use the append() function to add a fourth item - ‘pineapple’ - to the end of the array. The append() function is used to add elements to the end of an existing array. After running this code, my_arr will now contain four elements: ‘apple’, ‘banana’, ‘mango’, and ‘pineapple’.

python