Python List Index is another example of Python List Methods. With this method, we get the index of the find member in the list. This python method gives the first find member’s index.
Let’s do an example and for Python Index Method. Below, we will get the index of member 45.
numbers = [5,9,45,7,126,4] x = numbers.index(45) print(x)
The output will be 2, because “45” is the third member of this list, it is index 2. Remember, the indexes start from 0. This means that the first member of a list has index 0.
If we look fort he index of “5”, we will receive the below return.
numbers = [5,9,45,7,126,4] x = numbers.index(5) print(x)
This is also similar for string lists. For the below string list Python List Index example, we will receive 4 as a result. Because, “bb” is the fifth member of this list.
strings = ["aa","abc","aaa","a","bb"] x = strings.index("bb") print(x)
Python Index method is an important method for python lists. With this method, you can access any members’s index and use it for different aims.