Use the list index() method to Find the index of an element in the array Python. It returns the index in the list were the first instance of the
value passed in is found.
It returns the index of the first occurrence of the element that you want to find, or -1 if the element is not found.
Find the index of an element in array Python
Simple example code.
animals = ['cat', 'dog', 'rabbit', 'horse'] # get the index of 'dog' index = animals.index('dog') print("dog", index) print("rabbit", animals.index('rabbit'))
Do comment if you have any doubts or suggestions on this Python Array.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.