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.

 

By the way, index values start with 0. It means that the index of the first item in a list is 0. The second item in a list has index 1, the third has 2 and so on. So, to reach an item in a list, we give one lower number.

 

To understand this better, 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

 

 


You can also learn Python List Reverse Sort


 

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. You can learn other methods of lists in this Python Programming Training.

 

Back to: Python Programming Course > Python Lists

Leave a Reply

Your email address will not be published.

IPCisco is the Winner of 2019 “Best Certification Study Journey” Category! We are also Finalist of 2020 & 2021 in Cisco IT Blog Awards!

Cisco-ITBlogAwards-2019-Winner-IPCisco-k
ITBlogAwards_2020_Badge-Finalist-BestCertStudy-ipcisco
ITBlogAwars-2021-ipcisco

Python Programming Course

Collapse
Expand
IPCisco on Social Media!

Latest Blog Posts

top-ten-network-certifications-ipcisco
metaverse-jobs-ipcisco.com
Wifi-6-vs-wifi-5-ipcisco.com
16-Reasons-To-Learn-Linux
gns3-vm-ware-installation-guide