The index method does not do what you expect. To get an item at an index, you must use the [] syntax:

>>> my_list = ['foo', 'bar', 'baz']
>>> my_list[1]  # indices are zero-based
'bar'

index is used to get an index from an item:

>>> my_list.index('baz')
2

If you're asking whether there's any way to get index to recurse into sub-lists, the answer is no, because it would have to return something that you could then pass into [], and [] never goes into sub-lists.

Answer from icktoofay on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_arrays.asp
Python Arrays
An array can hold many values under a single name, and you can access the values by referring to an index number.
Top answer
1 of 5
15

The index method does not do what you expect. To get an item at an index, you must use the [] syntax:

>>> my_list = ['foo', 'bar', 'baz']
>>> my_list[1]  # indices are zero-based
'bar'

index is used to get an index from an item:

>>> my_list.index('baz')
2

If you're asking whether there's any way to get index to recurse into sub-lists, the answer is no, because it would have to return something that you could then pass into [], and [] never goes into sub-lists.

2 of 5
6

list is an inbuilt function don't use it as variable name it is against the protocol instead use lst.

To access a element from a list use [ ] with index number of that element

lst = [1,2,3,4]
lst[0]
1

one more example of same

lst = [1,2,3,4]
lst[3]
4

Use (:) semicolon to access elements in series first index number before semicolon is Included & Excluded after semicolon

lst[0:3]
[1, 2, 3]

If index number before semicolon is not specified then all the numbers is included till the start of the list with respect to index number after semicolon

lst[:2]
[1, 2]

If index number after semicolon is not specified then all the numbers is included till the end of the list with respect to index number before semicolon

lst[1:]
[2, 3, 4]

If we give one more semicolon the specifield number will be treated as steps

lst[0:4:2]
[1, 3]

This is used to find the specific index number of a element

lst.index(3)
2

This is one of my favourite the pop function it pulls out the element on the bases of index provided more over it also remove that element from the main list

lst.pop(1)
2

Now see the main list the element is removed..:)

lst
[1, 3, 4]

For extracting even numbers from a given list use this, here i am taking new example for better understanding

lst = [1,1,2,3,4,44,45,56]

import numpy as np

lst = np.array(lst)
lst = lst[lst%2==0]
list(lst)
[2, 4, 44, 56]

For extracting odd numbers from a given list use this (Note where i have assingn 1 rather than 0)

lst = [1,1,2,3,4,44,45,56]

import numpy as np

lst = np.array(lst)
lst = lst[lst%2==1]
list(lst)
[1, 1, 3, 45]

Happy Learning...:)

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-array-indexing
Python Array Indexing - GeeksforGeeks
July 23, 2025 - import array # Create an array ... ... In Python, arrays support negative indexing where the last element of the array is accessed with index -1, the second-to-last element with index -2 and so on....
๐ŸŒ
Problem Solving with Python
problemsolvingwithpython.com โ€บ 05-NumPy-and-Arrays โ€บ 05.05-Array-Indexing
Array Indexing - Problem Solving with Python
Where <value> is the value stored in the array, <array> is the array object name and [index] specifies the index or location of that value. In the array above, the value 6 is stored at index 2.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_slicing.asp
NumPy Array Slicing
Slicing in python means taking elements from one given index to another given index. We pass slice instead of index like this: [start:end]. We can also define the step, like this: [start:end:step]. ... Note: The result includes the start index, but excludes the end index. Slice elements from index 4 to the end of the array:
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-array-tutorial-define-index-methods
Python Array Tutorial โ€“ Define, Index, Methods
January 31, 2022 - If there is more than one element with the same value, the index of the first instance of the value will be returned: import array as arr numbers = arr.array('i',[10,20,30,10,20,30]) #search for the index of the value 10 #will return the index number of the first instance of the value 10 print(numbers.index(10)) #output #0
Find elsewhere
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ user โ€บ basics.indexing.html
Indexing on ndarrays โ€” NumPy v2.4 Manual
The examples work just as well when assigning to an array. See Assigning values to indexed arrays for specific examples and explanations on how assignments work. Note that in Python, x[(exp1, exp2, ..., expN)] is equivalent to x[exp1, exp2, ..., expN]; the latter is just syntactic sugar for ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python array index
Python Array Index - Spark By {Examples}
May 31, 2024 - You can access a single element in an array by using its index. Use the index operator [] to access a specified element in an array. The index must be an integer. Letโ€™s create an array using the array module of Python and use the index [] ...
๐ŸŒ
W3Schools
w3schools.com โ€บ dsa โ€บ dsa_data_arrays.php
DSA Arrays
Learn more about Python lists here. Arrays are indexed, meaning that each element in the array has an index, a number that says where in the array the element is located.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ array indexing in python โ€“ beginnerโ€™s reference
Array Indexing in Python - Beginner's Reference - AskPython
February 22, 2021 - Letโ€™s perform arithmetic operations on individual elements of an array using indexing. ... 2-Dimensional arrays in Python can be accessed using value, row, and columns.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_search.asp
NumPy Searching Arrays
The return value is an array: [1 2 3] containing the three indexes where 2, 4, 6 would be inserted in the original array to maintain the order. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
๐ŸŒ
Python Data Science Handbook
jakevdp.github.io โ€บ PythonDataScienceHandbook โ€บ 02.07-fancy-indexing.html
Fancy Indexing | Python Data Science Handbook
For example, consider the following array: ... Suppose we want to access three different elements. We could do it like this: ... When using fancy indexing, the shape of the result reflects the shape of the index arrays rather than the shape of the array being indexed:
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_list_index.asp
Python List index() Method
Python DSA Lists and Arrays Stacks Queues Linked Lists Hash Tables Trees Binary Trees Binary Search Trees AVL Trees Graphs Linear Search Binary Search Bubble Sort Selection Sort Insertion Sort Quick Sort Counting Sort Radix Sort Merge Sort
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists_access.asp
Python - Access List Items
Python DSA Lists and Arrays Stacks Queues Linked Lists Hash Tables Trees Binary Trees Binary Search Trees AVL Trees Graphs Linear Search Binary Search Bubble Sort Selection Sort Insertion Sort Quick Sort Counting Sort Radix Sort Merge Sort
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-indexing
Numpy Array Indexing - GeeksforGeeks
December 17, 2025 - ... The combined condition selects elements greater than 10 and less than 30 resulting in [15, 20, 25]. It is also known as Advanced Indexing which allows us access elements of an array by using another array or list of indices.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_arrray_what_is.asp
Python What is an Array?
An array can hold many values under a single name, and you can access the values by referring to an index number. Python Array Tutorial Array Access Arrays Array Length Looping Array Elements Add Array Element Remove Array Element Array Methods ...
๐ŸŒ
Python Like You Mean It
pythonlikeyoumeanit.com โ€บ Module3_IntroducingNumpy โ€บ BasicIndexing.html
Introducing Basic and Advanced Indexing โ€” Python Like You Mean It
According to its definition, we must supply our array-indices as a tuple in order to invoke basic indexing. As it turns out, we have been forming tuples of indices all along! That is, every time that we index into an array using the syntax x[i, j, k], we are actually forming a tuple containing ...