How to Find the Index of Given Element of List in Python

In this tutorial, learn how to find the index of given element of list Using Python. The short answer is: use the Python index() to get the index of the list element.

In the list, the elements are sequentially arranged in the order using the index. The elements in the list are indexed which starts from zero(0). Each element of the list are enclosed within the square bracket([]). You may also like to read how to change or reverse the list elements using Python.

How to Find the Index of Given Element of List in Python

If you want to get the index of the element given in the list, you have to use the Python index(). The function takes one argument to pass to get the index. You have to pass the list element as the argument of the index() function.

You can get the position of the item in the list at a time. If you want to get the index of more elements, you have to use the index() function many times. Check the example given below to get the idea of getting the index of elements.

Output

0
1
2
4

The above example showing the use of the index() function to get the position of the list item. By using the above example, you can find the index of any type of element given in the list.

The given example finds the index of the string element as well as the integer element. The output showing the index value of the element given in the list.

I hope you like this post on how to get item position in the list in Python.

References