← Go Back

How to Find the Index of an Item in a List

The index() 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.

lists


🐍 You might also find interesting: