To find the index of a given item in a list in Python, you can use the index() method. This method returns the first index where the specified item is found. Here’s how it works conceptually:
Call the index() method on the list, passing the item you want to find as an argument.
If the item is present in the list, the method will return its index.
If the item is not in the list, a ValueError will be raised.
For example, if you have a list like [10, 20, 30, 40] and you want to find the index of 30, the result would be 2, as list indices in Python are zero-based.How can I find the index for a given item in a list in Python?