🌐
W3Schools
w3schools.com › python › ref_list_index.asp
Python List index() Method
Remove List Duplicates Reverse ... Q&A Python Bootcamp Python Training ... The index() method returns the position at the first occurrence of the specified value....
🌐
DataCamp
datacamp.com › tutorial › python-list-index
Python List index() Method Explained with Examples | DataCamp
March 28, 2025 - This function is especially useful ... Master Python for data science and gain in-demand skills. ... The method index() returns the lowest index in the list where the element searched for appears....
Discussions

python - How can I find the index for a given item in a list? - Stack Overflow
If the list is short it's no problem ... from a Python list, if it isn't then perhaps you should consider storing the elements in numpy array in the first place. ... I’m voting to close this question (in protest) because there are already 42 undeleted answers (and 16 more deleted) for a simple, one-liner reference question that almost all have the same built-in function at their core ... More on stackoverflow.com
🌐 stackoverflow.com
Help with .index()? finding multiple instances of item
The easy way would be to just use enumerate on the list, and then manually iterate the list and find the indices yourself. More on reddit.com
🌐 r/learnpython
9
3
March 11, 2023
Learning about list functions - Creating a new list from index values
You could try using a zip() to combine the two lists and then filter from that. It will end up looking something like: For index, value in zip(input_list, value_list): I’ll let you carry on from there, but it essentially works the same way as unpacking a dictionary’s .items() Hope this gets you going in the right direction Edit ::: link for .zip() explanation https://www.w3schools.com/python/ref_func_zip.asp More on reddit.com
🌐 r/learnpython
7
1
November 20, 2022
Find the index of the minimum value in a list?
You could try a.index(min(a)) More on reddit.com
🌐 r/learnpython
12
2
June 18, 2015
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-index
Python List index() - Find Index of Item - GeeksforGeeks
index() method in Python is a helpful ... in a list. It works by searching through the list from the beginning and returning the index (position) of the first occurrence of the element you're looking for....
Published   April 27, 2025
🌐
Programiz
programiz.com › python-programming › methods › list › index
Python List index()
The index() method returns the index of the specified element in the list.
🌐
Codecademy
codecademy.com › docs › python › lists › .index()
Python | Lists | .index() | Codecademy
June 11, 2025 - The .index() method always returns the index of the first occurrence of the element. If you need to find all occurrences, use a list comprehension with enumerate() or implement a custom search function.
🌐
Sentry
sentry.io › sentry answers › python › get the index of a list item in python
Python Index of Item in List Using list.index() | Sentry
2 weeks ago - We can use Python’s list.index() method to return the index of a given item: mylist = ["run", "hop", "bop"] print(mylist.index("hop")) # will print 1 · If the given item is not found in the list, a ValueError will be raised.
🌐
Scaler
scaler.com › home › topics › index() in python
Python List index() Method (With Examples) - Scaler Topics
March 30, 2022 - The index() method in Python searches an element in the list and returns its position/index. If there are duplicate elements, then by default, index() returns the position of the first occurrence of the element we are searching for in the list.
🌐
Kochiva
kochiva.com › home › python list index( ) method – explained with practical examples
Python List Index() Method - Explained with Practical Examples
September 26, 2024 - The index () method in Python is used to find the index position of the element or the desired element itself in a list, string, or data structure. For example, if you have a list of students in the commerce section in order of decreasing marks ...
Find elsewhere
🌐
StrataScratch
stratascratch.com › blog › how-to-get-the-index-of-an-item-in-a-list-in-python
How to Get the Index of an Item in a List in Python - StrataScratch
September 6, 2024 - For example, 25 comes first with an index value of 0, and the second with the lowest value will make you get my point right. A function called index tells you the position of an item in a list.
🌐
Skill Matrix Academy
skillsmatrixacademy.com › home › python list index() method explained with practical examples
Python list index() Method Explained with Practical Examples
November 7, 2025 - As mentioned earlier, if you want to find the position of an element in a list in Python, you can use the index() method. This built-in Function quickly locates the element and returns its index within the list.
🌐
Toppr
toppr.com › guides › python-guide › references › methods-and-functions › methods › list › index › python-list-index
Python List index() function | Why do we use Python list index() function? |
September 20, 2021 - The Python list index() function is used to return the index value of the specified element in the list. The Python list index() is a built-in function that searches for a specified element from the beginning of the list and returns the lowest ...
🌐
freeCodeCamp
freecodecamp.org › news › indices-of-a-list-in-python-list-indexof-equivalent
Indices of a List in Python – List IndexOf() Equivalent
April 6, 2023 - Apart from the item you want to search for, the index() method also takes the optional parameters start and stop. start is the position you want the index() method to start looking for the item, and stop is the position you want it to stop searching ...
🌐
Tutorialspoint
tutorialspoint.com › python › list_index.htm
Python List index() Method
The Python List index() method is used to retrieve the lowest index in a list at which a specified object appears. The object can be anything; a single element or a collection of elements in the form of another list, tuple, set etc.
🌐
Simplilearn
simplilearn.com › home › resources › software development › python index: mastering list indexing techniques
Python List index() Method Explained with Examples
3 weeks ago - The Python index() method helps you find the index position of an element or an item in a string of characters or a list of items.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Analytics Vidhya
analyticsvidhya.com › home › how can i manipulate python list elements using indexing?
How can I Manipulate Python List Elements Using Indexing?
January 22, 2024 - In this example, since the element 10 is present in my_list, the message “Element found” is printed. ... The index() function, a built-in method in Python, returns the index of the first occurrence of a specified element in a list:
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.6 documentation
Remove all items from the list. Similar to del a[:]. ... Return zero-based index of the first occurrence of value in the list.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › python list index method
Python List index() Method
December 4, 2024 - understanding the Python List Index Method is paramount. Python offers a robust function called index() which allows you to search for a particular element in a list and retrieve the index of its initial appearance.
🌐
iO Flood
ioflood.com › blog › index-python
index() Python Function Guide (With Examples)
February 10, 2024 - In this example, we have a list my_list containing three items. We use the index() function to find the position of ‘banana’ in the list. The function returns ‘1’, which is the index position of ‘banana’. Remember, Python list indexing starts from 0.
Top answer
1 of 16
6115
>>> ["foo", "bar", "baz"].index("bar")
1

See the documentation for the built-in .index() method of the list:

list.index(x[, start[, end]])

Return zero-based index in the list of the first item whose value is equal to x. Raises a ValueError if there is no such item.

The optional arguments start and end are interpreted as in the slice notation and are used to limit the search to a particular subsequence of the list. The returned index is computed relative to the beginning of the full sequence rather than the start argument.

Caveats

Linear time-complexity in list length

An index call checks every element of the list in order, until it finds a match. If the list is long, and if there is no guarantee that the value will be near the beginning, this can slow down the code.

This problem can only be completely avoided by using a different data structure. However, if the element is known to be within a certain part of the list, the start and end parameters can be used to narrow the search.

For example:

>>> import timeit
>>> timeit.timeit('l.index(999_999)', setup='l = list(range(0, 1_000_000))', number=1000)
9.356267921015387
>>> timeit.timeit('l.index(999_999, 999_990, 1_000_000)', setup='l = list(range(0, 1_000_000))', number=1000)
0.0004404920036904514

The second call is orders of magnitude faster, because it only has to search through 10 elements, rather than all 1 million.

Only the index of the first match is returned

A call to index searches through the list in order until it finds a match, and stops there. If there could be more than one occurrence of the value, and all indices are needed, index cannot solve the problem:

>>> [1, 1].index(1) # the `1` index is not found.
0

Instead, use a list comprehension or generator expression to do the search, with enumerate to get indices:

>>> # A list comprehension gives a list of indices directly:
>>> [i for i, e in enumerate([1, 2, 1]) if e == 1]
[0, 2]
>>> # A generator comprehension gives us an iterable object...
>>> g = (i for i, e in enumerate([1, 2, 1]) if e == 1)
>>> # which can be used in a `for` loop, or manually iterated with `next`:
>>> next(g)
0
>>> next(g)
2

The list comprehension and generator expression techniques still work if there is only one match, and are more generalizable.

Raises an exception if there is no match

As noted in the documentation above, using .index will raise an exception if the searched-for value is not in the list:

>>> [1, 1].index(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 2 is not in list

If this is a concern, either explicitly check first using item in my_list, or handle the exception with try/except as appropriate.

The explicit check is simple and readable, but it must iterate the list a second time. See What is the EAFP principle in Python? for more guidance on this choice.

2 of 16
725

The majority of answers explain how to find a single index, but their methods do not return multiple indexes if the item is in the list multiple times. Use enumerate():

for i, j in enumerate(['foo', 'bar', 'baz']):
    if j == 'bar':
        print(i)

The index() function only returns the first occurrence, while enumerate() returns all occurrences.

As a list comprehension:

[i for i, j in enumerate(['foo', 'bar', 'baz']) if j == 'bar']

Here's also another small solution with itertools.count() (which is pretty much the same approach as enumerate):

from itertools import izip as zip, count # izip for maximum efficiency
[i for i, j in zip(count(), ['foo', 'bar', 'baz']) if j == 'bar']

This is more efficient for larger lists than using enumerate():

$ python -m timeit -s "from itertools import izip as zip, count" "[i for i, j in zip(count(), ['foo', 'bar', 'baz']*500) if j == 'bar']"
10000 loops, best of 3: 174 usec per loop
$ python -m timeit "[i for i, j in enumerate(['foo', 'bar', 'baz']*500) if j == 'bar']"
10000 loops, best of 3: 196 usec per loop
🌐
FavTutor
favtutor.com › blogs › get-list-index-python
Python Find String Position in List (Get the Index of an Item)
1 week ago - Maybe it's "Ravi" and you want the slot number so you can update the next value, or check a matching list at the same spot. That's the everyday job of finding the position of a string in a list, and Python gives you a few ways to do it depending on what you actually need. The short answer is the index() method.