The index() technique returns the index of the required element within the list.
The syntax of the list index() technique is:
list.index(element, start, end)
list index() parameters
The list index() technique can take a most of 3 arguments:
element - the detail to be searched
start (optional) - begin looking from this index
end (optional) - seek the detail as much as this index
Return Value from List index()
The index() technique returns the index of the given element within the list.
If the element isn't found, a ValueError exception is raised.
Note: The index() technique most effectively returns the primary prevalence of the matching element
# vowels list
vowels = ['a', 'e', 'i', 'o', 'i', 'u']
# index of 'e' in vowels
index = vowels.index('e')
print('The index of e:', index)
# element 'i' is searched
# index of the first 'i' is returned
index = vowels.index('i')
print('The index of i:', index)
Output
The index of e: 1
The index of i: 2
Top comments (0)