How to Find Index of Item in Python List Last Updated : 26 Dec, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report To find the index of given list item in Python, we have multiple methods depending on specific use case. Whether we’re checking for membership, updating an item or extracting information, knowing how to get an index is fundamental. Using index() method is the simplest method to find index of list item. Using index()index() method returns the index of first occurrence of a specified value. If the item is not found, it raises a ValueError.Example: Python a = [10, 20, 30, 40, 50] # Find index of item 30 res = a.index(30) print(res) Output2 Note: To handle a ValueError, we can use a try-except block. This prevents the program from crashing when the item is not found.Let's explore other methods to find the index in a Python list.Table of ContentUsing enumerate() Using for LoopUsing enumerate() If we want to find the index of an item while iterating over the list, we can use enumerate() function. This is helpful when we are searching for an item during iteration.Example: Python a = [10, 20, 30, 40, 50] # `i` is the index, `val` is the value at that index res = [i for i, val in enumerate(a) if val == 30] print(res) Output[2] Using for LoopWithin each iteration, we check if the current element is equal to the specified item. If a match is found, we print found index and exit the loop using the break statement. Example: Python a = [10, 20, 30, 40, 50] item = 30 # element to find # looping the list for i in range(len(a)): if a[i] == item: print(i) break # found Output2 Comment More infoAdvertise with us Next Article Python - Find Index containing String in List A anjalibo6rb0 Follow Improve Article Tags : Python Python Programs python-list Python list-programs How To +1 More Practice Tags : pythonpython-list Similar Reads How To Find the Length of a List in Python The length of a list refers to the number of elements in the list. There are several methods to determine the length of a list in Python. For example, consider a list l = [1, 2, 3, 4, 5], length of this list is 5 as it contains 5 elements in it. Let's explore different methods to find the length of 2 min read Python - Ways to find indices of value in list In Python, it is common to locate the index of a particular value in a list. The built-in index() method can find the first occurrence of a value. However, there are scenarios where multiple occurrences of the value exist and we need to retrieve all the indices. Python offers various methods to achi 3 min read How to Find Index of a Substring in Python In Python, sometimes we need to know where a certain substring appears in a string. To do this, we can find the index (or position) of that substring. The index tells us where the substring is located. Letâs look at some simple ways to find the index of a substring in a string.Using find() methodThe 2 min read How to Check if an Index Exists in Python Lists When working with lists in Python, sometimes we need to check if a particular index exists. This is important because if we try to access an index that is out of range, we will get an error. Let's look at some simple ways to check if an index exists in a Python list.The easiest methods to check if g 2 min read Python - Find Index containing String in List In this article, we will explore how to find the index of a string in a list in Python. It involves identifying the position where a specific string appears within the list.Using index()index() method in Python is used to find the position of a specific string in a list. It returns the index of the 2 min read Python - Find starting index of all Nested Lists In this article given a matrix, the task is to write a Python program to compute the starting index of all the nested lists. Example: Input : test_list = [[5], [9, 3, 1, 4], [3, 2], [4, 7, 8, 3, 1, 2], [3, 4, 5]] Output : [0, 1, 5, 7, 13] Explanation : 1 + 4 = lengths of 2 initial lists = 5, 3, of 3 8 min read Like