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 list element 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 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 index of elements.
myList = ["one", "two", 37, "four", 51];
The above example showing the use of index function to get the position of list item. By using the above example, you can find the index of any type of element given in the list.
The given example find 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.
Hope, you like this post of how to get item position in list in Python. If you have any query regarding the tutorial, please comment below.
- Stackoverflow Discussion on index() in Python
- Geeksforgeeks Tutorial on Python List Index
- Programiz Tutorial on Python List Index()
Also tell me, which method you are using to get the index of the list element.