Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement list access by python

Shulou Source: shulou.com Published: 2022-06-03 05:05:59 10月02日 Update

This article mainly introduces python how to achieve list access, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

1. Directly access the element through the index. The element range is [0, list length-1]. If it is exceeded, an exception is thrown and the current access value is returned.

Visit1 = [1,2,3,4,5,6,7,8,9,0] print (visit1 [0]) # 1

2. Index () gets the index position where the specified element appears for the first time in the list.

Visit2 = ["sss", "a", "b", "c"] print (visit2.index ("sss")) # 0print (visit2.index ("b", 2)) # 2 Thank you for reading this article carefully. I hope the article "how to achieve list access in python" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Article element index value location interest at the same time more friends knowledge editing scope industry information information channel length channel reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Huawei Redmi Shulou Information Docker