Python List Index

python-list-index-1-ipcisco

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.

 

2

python-list-index-1-ipcisco

 

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)

 

 

 

python-list-index-2-ipcisco

 

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)
4

 

 

how-to-access-items-of-a-python-list

 

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.

 

Back to: Python Programming Course > Python Lists

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact

  • info@ipcisco.com
IPCisco is the Winner! “Best Certification Study Journey of 2019!”

Cisco-ITBlogAwards-2019-Winner-IPCisco-k