What are the usage characteristics of python slices
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!