You are on page 1of 2

Array insert operation

from array import *

array1 = array('i', [10,20,30])

array1.insert(1,60)

for x in array1:

print(x)

to_insert = int(input("Enter the index: "))

new_element = int(input("Enter the new Element: "))

arr.insert(to_insert, new_element)

delete

from array import *

array1 = array('i', [10,20,30,40])

array1.remove(30)

for x in array1:

print(x)

to_remove = int(input("Enter the value to remove: "))

arr.remove(to_remove)

search

from array import *

array1 = array('i', [10,20,30,40])

print(array1.index(30))

to_srch = int(input("Enter the value to search: "))

print(arr.index(to_srch))

update

from array import *

array1 = array('i', [10,20,30,40,50])

array1[2] = 80

for x in array1:

upt_ind = int(input("Index to Update: "))


new_value = int(input("Enter New Element/Value: "))

arr[upt_ind] = new_value

You might also like