DEV Community

I'm Just a Guy with a Computer
I'm Just a Guy with a Computer

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more