What you show, ('A','B','C','D','E'), is not a list, it's a tuple (the round parentheses instead of square brackets show that). Nevertheless, whether it to index a list or a tuple (for getting one item at an index), in either case you append the index in square brackets.

So:

thetuple = ('A','B','C','D','E')
print thetuple[0]

prints A, and so forth.

Tuples (differently from lists) are immutable, so you couldn't assign to thetuple[0] etc (as you could assign to an indexing of a list). However you can definitely just access ("get") the item by indexing in either case.

Answer from Alex Martelli on Stack Overflow
🌐
Programiz
programiz.com › python-programming › methods › list › index
Python List index()
The index() method returns the index of the given element in the list. If the element is not found, a ValueError exception is raised.
Discussions

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
python - How can I find the index for a given item in a list? - Stack Overflow
However, if you are going to search your data more than once then I recommend using bisect module. Keep in mind that using bisect module data must be sorted. So you sort data once and then you can use bisect. Using bisect module on my machine is about 20 times faster than using index method. Here is an example of code using Python 3.8 and above syntax: import bisect from timeit import timeit def bisect_search(container, value... More on stackoverflow.com
🌐 stackoverflow.com
Accessing dictionary value by index in python - Stack Overflow
I would like to get the value by key index from a Python dictionary. More on stackoverflow.com
🌐 stackoverflow.com
How to get a random value from a table(SQLite)?
Why are you trying to do this? Anyway, if it's just two numeric columns and unless you have continuous IDs, just read the whole table into memory, generate the random index and choose the right row. If the amount of data is an issue, for determining the index you really need just the SELECT COUNT(*). When you have the index, you can use SELECT with LIMIT to pick the Nth row. If you do have continuous IDs (starting from 1 or something similar), you can just use SELECT with WHERE id=... to pick the Nth row. More on reddit.com
🌐 r/learnprogramming
8
2
April 9, 2012
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-accessing-index-and-value-in-list
Accessing index and value in Python list - GeeksforGeeks
July 11, 2025 - For example, using enumerate(list) in a loop like for index, value in enumerate(list) allows us to access both the index and the value together. enumerate() is preferred and most efficient method for accessing both index and value in Python.
🌐
TutorialsPoint
tutorialspoint.com › accessing-index-and-value-in-a-python-list
Accessing index and value in a Python list
The index() method returns the position of a specific element in the list ? numbers = [11, 45, 27, 8, 43] print("Index of 45:", numbers.index(45)) days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] print("Index of Wed:", days.index('Wed')) ...
🌐
DataCamp
datacamp.com › tutorial › python-list-index
Python List index() Method Explained with Examples | DataCamp
March 28, 2025 - The position returned is 0, because 3 first appears in the first position or the 0th index in Python. Here is what's happening internally: The index is going through all values starting from the 1st position (0th index), looking for the element you are searching for. When it finds the value - it returns the position and exits the system. However, this is not too efficient when going through a large list, and you need to get the position of something towards the end of the list.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-index
Python List index() - Find Index of Item - GeeksforGeeks
Example: In this example, index() is used to find the position of an element in a list. ... Explanation: a.index("dog") searches for "dog" in the list and element is found at index 1, so 1 is returned. ... Return Value: Returns the index of the first matching occurrence and raises ValueError if the element is not found. Example 1: In this example, the search is limited to a specific portion of the list using the start and end parameters.
Published   6 hours ago
🌐
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 - Lists are, hence, an essential ingredient of your Python toolkit. ages = [25, 30, 22, 26, 32] first_age = ages[0] print(first_age) Here is the output. In this list, the first age, 25, is at index 0, the second age, 30, is at index 1, and so on. After sorting, the index position tells which age is at what place in the list. 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.
🌐
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 - The value for end parameter would then be the length of the list minus 1. The index of the last item in a list is always one less than the length of the list. So, putting all that together, here is how you could try to get all three instances of the item: programming_languages = ["JavaScript","Python","Java","Python","C++","Python"] print(programming_languages.index("Python",1,5)) #output #1
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Index.values.html
pandas.Index.values — pandas 3.0.4 documentation - PyData |
Reference to the underlying data. ... A NumPy array representing the underlying data. ... >>> idx = pd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='int64') >>> idx.values array([1, 2, 3])
🌐
Flexiple
flexiple.com › python › python-program-accessing-index-value-list
Python Program To Accessing Index And Value In A List - Flexiple
March 18, 2024 - These functions return the n smallest or largest elements from the list, respectively. To access both index and value, we can use enumerate to pair each element with its index before using heapq.
🌐
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 - The Python index method gets the index value for an item in an array or a string. Learn how to use the index method on Career Karma.
🌐
Sentry
sentry.io › sentry answers › python › get the index of a list item in python
Get the index of a list item in Python
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.
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
🌐
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 - # print(l.index(100)) # ValueError: 100 is not in list ... String objects (str) have a find() method that returns -1 if a substring is not present. However, no such method exists for lists (as of Python 3.11). Search for a string in Python (Check if a substring is included/Get a substring position) To create a function that emulates the behavior of the find() method for lists, use the in operator to check if an item is in the list.
🌐
GeeksforGeeks
geeksforgeeks.org › python › access-the-index-and-value-using-python-for-loop
Access the Index and Value using Python 'For' Loop - GeeksforGeeks
July 23, 2025 - In this example, we have used itertools to access the index value in a for loop. ... from itertools import count # Sample list fruits = ['apple', 'banana', 'orange'] # Create an iterator that produces consecutive integers starting from 0 index_counter = count() # Use zip to combine the index_counter with the list elements for i, fruit in zip(index_counter, fruits): print(f&quot;Index: {i}, Value: {fruit}&quot;)