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)
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
Top comments (0)