🌐
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....
🌐
W3Schools
w3schools.com › python › ref_list_index.asp
Python List index() Method
Python Examples Python Compiler ... Q&A Python Bootcamp Python Training ... The index() method returns the position at the first occurrence of the specified value....
🌐
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 - The index() Function helps you find the position of an element in a list or string. It searches for the first match and returns its index number (or position). ... This will output 2, because in Python indexing, the count starts at 0.
🌐
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 is a built-in Python list method that returns the index position of the first occurrence of a specified element within a list.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-index
Python List index() - Find Index of Item - GeeksforGeeks
index() method in Python is a helpful tool when you want to find the position of a specific item 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 ...
Published   April 27, 2025
🌐
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
🌐
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.
Find elsewhere
🌐
Hyperskill
hyperskill.org › university › python › indexes-and-index-in-python
Indexes and index() in Python
July 17, 2024 - It serves as an identifier to access specific elements in a list. The concept of Python index is useful in finding the location or position of a particular element within a list. Python provides the index() function, which allows us to find the first occurrence of a given element in a list.
🌐
Tutorial Gateway
tutorialgateway.org › python-index-list-function
Python List index function
March 26, 2025 - The Python index function finds the index position of an item from a given list. We show multiple examples on the list strings and integers.
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
🌐
AskPython
askpython.com › home › the python index() method
The Python index() Method - AskPython
August 6, 2022 - Note: the index() method works in the same manner for tuples too. Coming to strings, the member function Python index() returns the minimum index at which the starting of the specified substring is found.
🌐
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 ...
🌐
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. Therefore, we need to either wrap our function call in a try/except block or first check whether the item is in the list.
🌐
Career Karma
careerkarma.com › blog › python › python index: a step-by-step guide
Python Index: A Step-By-Step Guide | Career Karma
December 1, 2023 - For this tutorial, we are going to look at the index() method in-depth, with reference to an example. The Python index() method returns the index position of an item in a list or a character or range of characters in a string.
🌐
PW Skills
pwskills.com › blog › data analytics › index function in python: complete explanation with examples
Index Function In Python: Complete Explanation With Examples
November 4, 2025 - In Python, list or string index() returns the index of a given element. If the value is not found in the list then you will get a valueError in the return value. Remember that when you are using the index function in Python, then it will only ...
🌐
Python
docs.python.org › 3 › genindex-I.html
Index — Python 3.14.6 documentation
Navigation · index · modules · Python » · 3.14.6 Documentation » · Index · Theme · Light · Index – I
🌐
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 - Python has several methods and hacks for getting the index of an item in iterable data like a list, tuple, and dictionary. In this article, we are looking at how you can get the index of a list item with the index() method. I’ll also show you a function that is equivalent to the index() method.
🌐
W3Schools
w3schools.com › python › ref_string_index.asp
Python String index() Method
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Training ... The index() method finds the first occurrence of the specified value....