Friday, April 13, 2018

How to search an element in Arrays?


Search Operation

You can perform a search for an array element based on its value or its index. Here, we search a data element using the python in-built index method.

from array import *

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

print (array1.index(40))

When we compile and execute the above program, it produces the following result which shows the index of the element. If the value is not present in the array then the program returns an error.

Output

3