DEV Community

Tommi k Vincent
Tommi k Vincent

Posted on

Search Operation in Arrays in python.

a search operation can be performed on an element based on its value or index.

we search a data element using the python in-built index() method. Enter the following code in a python file and try to execute it.


from array import *

vincente = array('i', [10, 20, 30, 40, 50, 70, 80])


index = vincente.index(50)
Enter fullscreen mode Exit fullscreen mode

output
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

Index of 50: 4
Enter fullscreen mode Exit fullscreen mode

Top comments (0)