Python Language Insert value in an array using insert() method


We can use the insert() method to insert a value at any index of the array. Here is an example :

my_array = array('i', [1,2,3,4,5])
#array('i', [0, 1, 2, 3, 4, 5])

In the above example, the value 0 was inserted at index 0. Note that the first argument is the index while second argument is the value.