How to find the index of the first element with the specified value in list in Python

You can find the index of the first element with the specified value in list in Python by following the given step. If you want to learn Python then I will highly recommend you to read This Book.

How to find the index of the first element with the specified value
How to find the index of the first element with the specified value

Step 1

Index method is used to find the index of the first element with the specified value in list in Python. In the following example, I will find the index of integer ‘2’ in the list.

a = [1,2,2,3,2,4,5,2,1]
print(a)
print(a.index(2))

Example: In case of String

a = ['a','b','f','b','g','f','m']
print(a.index('f'))

People are also reading:

What is Computer Vision? Examples, Applications, Techniques

Top 10 Python Books | Best Python Books

Top 10 Computer Vision Books

Leave a Comment

Your email address will not be published.