Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the usage characteristics of python slices

Shulou Source: shulou.com Published: 2022-06-03 13:49:54 10月16日 Update

This article mainly introduces the characteristics of the use of python slices, 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. Specify the index of the first and last elements.

Names = ["Jerry", "Tom", "Bob", "Ann"] print (names [0:2]) # like the range method, # output:# ['Jerry',' Tom']

2.Only specifying the index of the last element will start automatically.

Names = ["Jerry", "Tom", "Bob", "Ann"] print (names [: 2]) # output:# ['Jerry',' Tom']

3.Only specify that the index of the first element will last until the end of the list.

Names = ["Jerry", "Tom", "Bob", "Ann"] print (namespace [1:]) # output:# ['Tom',' Bob', 'Ann']

4. Specify the third parameter and specify that one is extracted every few elements.

Names = ["Jerry", "Tom", "Bob", "Ann"] print (names0: 4:2]) # output:# ['Jerry',' Bob'] Thank you for reading this article carefully. I hope the article "what are the characteristics of the use of python slices" shared by the editor will be helpful to you? at the same time, I also hope you can support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

Tags: Element article index feature three value interest parameter at the same time method more friends end knowledge editing industry information information channel channel reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Shulou Tech Info vpn Redmi