>>> ["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.

Answer from Alex Coventry on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-index
Python List index() - Find Index of Item - GeeksforGeeks
index() method is used to find the position of an element in a list. It searches the list from left to right and returns the index of the first matching occurrence.
Published: July 17, 2026
🌐
W3Schools
w3schools.com › python › ref_list_index.asp
Python List index() Method
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
Discussions

python - How can I find the index for a given item in a list? - Stack Overflow
I do not recall needing list.index, myself. However, I have looked through the Python standard library, and I see some excellent uses for it. There are many, many uses for it in idlelib, for GUI and text parsing. The keyword module uses it to find comment markers in the module to automatically ... More on stackoverflow.com
🌐 stackoverflow.com
Python - How to find the index of a value?
You could increment index in the for loop, or you could use enumerate for index, key in enumerate(todoList): However, the index position of an item in a dictionary is not particularly meaningful. AFAIK the items are insertion ordered, but that's just an implementation detail and is not guaranteed by the language specification. The point of dictionaries is that you look things up by key, not index. If you want a list, use a list. More on reddit.com
🌐 r/learnprogramming
2
3
November 14, 2022
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
Why no .get(idx[, default]) on python list??
There was a lengthy thread on this on Python-Ideas a couple of years ago: https://mail.python.org/archives/list/python-ideas@python.org/thread/LLK3EQ3QWNDB54SEBKJ4XEV4LXP5HVJS/ The clearest explanation of the most common objection was from Marc-Andre Lemburg: dict.get() was added since the lookup is expensive and you want to avoid having to do this twice in the common case where the element does exist. It was not added as a way to hide away an exception, but instead to bypass having to generate this exception in the first place. dict.setdefault() has a similar motivation. list.get() merely safes you a line of code (or perhaps a few more depending on how you format things), hiding away an exception in case the requested index does not exist. If that's all you want, you're better off writing a helper which hides the exception for you. I argue that making it explicit that you're expecting two (or more) different list lengths in your code results in more intuitive and maintainable code, rather than catching IndexErrors (regardless of whether you hide them in a method, a helper, or handle them directly). So this is more than just style, it's about clarity of intent. More on reddit.com
🌐 r/Python
94
144
June 23, 2022
🌐
Programiz
programiz.com › python-programming › methods › list › index
Python List index() (with Code Visualization)
models = ['Claude', 'ChatGPT', 'Gemini', 'ChatGPT'] # Search 'ChatGPT' from start to end index = models.index('ChatGPT') print(index) # Output: 1 # Search 'ChatGPT' from index 2 to end index = models.index('ChatGPT', 2) print(index) # Output: 3 # Search 'ChatGPT' from index 2 to index 3 (exclusive) index = models.index('ChatGPT', 2, 3) print(index) # ValueError: 'ChatGPT' is not in list · Note: Python also supports negative indexing and you can use negative start and end indices with index().
🌐
freeCodeCamp
freecodecamp.org › news › python-find-in-list-how-to-find-the-index-of-an-item-or-element-in-a-list
Python Find in List – How to Find the Index of an Item or Element in a List
February 24, 2022 - Use the index() method to find the index of an item 1.Use optional parameters with the index() method · Get the indices of all occurrences of an item in a list · Use a for-loop to get indices of all occurrences of an item in a list · Use ...
Top answer
1 of 16
6114
>>> ["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
726

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
🌐
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 - Otherwise, Python raises a ValueError. However, it will break your program if it is not handled correctly. ... Consider you are reading sensor readings and want to get the first occurrence of a specific type of reading. You should try catching it here so the program will not crash and produce an error if no such reading exists. sensor_readings = [50, 55, 60, 65, 70] def find_reading_index(reading, readings): try: return readings.index(reading) except ValueError: return "Reading not found in the list" result = find_reading_index(65, sensor_readings) print(result) result_not_found = find_reading_index(75, sensor_readings) print(result_not_found)
🌐
DataCamp
datacamp.com › tutorial › python-list-index
Python List index() Method Explained with Examples | DataCamp
March 28, 2025 - In this tutorial, you will learn about the Python index() function. The index() method searches an element in the list and returns its position/index. First, this tutorial will introduce you to lists, and then you will see some simple examples of how to work with the index() function.
Find elsewhere
🌐
FavTutor
favtutor.com › blogs › get-list-index-python
Get the Index of an Element in a List in Python | FavTutor
July 19, 2026 - I enjoy sharing my technical knowledge as a content writer to help the community. Connect on LinkedIn → · In Python, you get the index of an element in a list with the index() method: my_list.index(value) returns the position of the first match.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-find-the-index-for-a-given-item-in-a-python-list
How to Find Index of Item in Python List - GeeksforGeeks
July 23, 2025 - 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. ... a = [10, 20, 30, 40, 50] # `i` is the index, `val` is the value at ...
🌐
Built In
builtin.com › software-engineering-perspectives › python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
An illustration of how the str.find() method works in Python. | Image: Indhumathy Chelliah · The string is banana. The substring is an. The substring occurs two times in the string. str.find(“an”) returns the lowest index of the substring an.
🌐
Mimo
mimo.org › tutorials › python › how-to-find-index-of-element-in-list-in-python
How to Find Index of Element in List in Python
Handle missing values with try/except ValueError or if value in my_list. Use enumerate() to find an index by condition. Use a comprehension with enumerate() to get all matching indexes. Use the start argument to find the next occurrence. ... Become a Python developer.
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-index-of-element-in-array-in-python
Find index of element in array in python - GeeksforGeeks
July 23, 2025 - We can use an index() method or a simple for loop to accomplish this task. index() method is the simplest way to find the index of an element in an array. It returns the index of the first occurrence of the element we are looking for.
🌐
GeeksforGeeks
geeksforgeeks.org › python-ways-to-find-indices-of-value-in-list
Python - Ways to find indices of value in list - GeeksforGeeks
December 10, 2024 - 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.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Find the Index of an Item in a List in Python | note.nkmk.me
July 27, 2023 - In Python, the index() method allows you to find the index of an item in a list. Built-in Types - Common Sequence Operations — Python 3.11.4 documentation How to use the index() method of a list Impl ...
🌐
Simplilearn
simplilearn.com › home › resources › software development › python index: mastering list indexing techniques
Python List index() Method Explained with Examples
July 12, 2026 - 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
🌐
Python Guides
pythonguides.com › get-index-of-element-in-python-list
Find Element Positions Using Python List Index Method
December 29, 2025 - I always wrap my index searches in a try-except block to ensure my code remains robust. # Python list of US tech companies tech_firms = ["Apple", "Microsoft", "Google", "Amazon"] search_term = "Meta" try: # Attempting to find the Python index position = tech_firms.index(search_term) print(f"{search_term} found at index {position}") except ValueError: # Handling the case where the item is missing from the Python list print(f"Sorry, {search_term} is not in the Python list.")
🌐
Temp Mail
tempmail.us.com › temp mail › blog › python › locating an item's index in a python list
Locating an Item's Index in a Python List - Temp Mail
July 24, 2024 - The item "bar" is called with the .index() method in order to acquire its position given a list my_list including components such as ["foo", "bar", "baz"]. The method returns the item's index if it is in the list, and it prints the index after that.
🌐
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
July 3, 2026 - 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.
🌐
iO Flood
ioflood.com › blog › python-get-index-of-item-in-list
Python Get Index of Item In List | 3 Simple Methods
June 29, 2024 - In the next section, we’ll discuss how to handle such scenarios and more advanced use cases. While Python’s list.index() function is a handy tool for finding the index of an item in a list, it’s not the only way.