An array
in Python is used to store multiple values of the same data type in a single variable.
The insert()
function is used to insert an item into an array to any specified index position.
insert(i, x)
Parameters | Description |
i | This is a required parameter. It is the index position you want the item to be inserted in the array. |
x | This is a required parameter. It is the value you want to insert into an array. |
Now, let’s create an array and insert a new item into the array:
# importing the array moduleimport array as arr# creating an integer data type arrayx = arr.array('i', [1,2,3,4,5,6,7])# using the insert functionx.insert(3, 10)# printing the new arrayprint(x)