index() is an inbuilt function in Python, which searches for given element from start of the list and returns the lowest index where the element appears.
list_name.index(element, start, end)
element - The element whose lowest index will be returned. start (Optional) - The position from where the search begins. end (Optional) - The position from where the search ends.
Returns lowest index where the element appears.
If any element which is not present is searched, it returns a ValueError
Code #1 :
Code #2 :
7 4 3
Code #3 :
Code #4 : ValueError
Traceback (most recent call last): File "/home/b910d8dcbc0f4f4b61499668654450d2.py", line 8, in print(list1.index(10)) ValueError: 10 is not in list
- Python | Replace elements in second list with index of same element in first list
- Python | Add list elements with a multi-list based on index
- Python | Sort list of list by specified index
- Python | Accessing index and value in list
- Python | Index of Non-Zero elements in Python list
- Python | Equate two list index elements
- Python | Returning index of a sorted list
- Python | Check for Nth index existence in list
- Python | Subgroups of i'th index size in list
- Python - K difference index pairing in list
- Python | Initializing dictionary with list index-values
- Python | Accumulative index summation in tuple list
- Python | Find mismatch item on same index in two list
- Python | Minimum K records of Nth index in tuple list
- Python | Initializing dictionary with list index values
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.