← Go Back
If the element is not found in the list, the
How to Find the Index of an Item in a List
Theindex()
list method takes an item and returns its position:>>> languages = ["Python", "C", "C++", "Elixir"]
>>> languages.index("C++")
2
If the element is not found in the list, the
ValueError
exception is thrown. When an element is repeated, the index of the first occurrence is returned.🐍 You might also find interesting: