How python splits sequences
This article mainly introduces how to split the sequence of python, 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.
Segmented sequence
Common sequence types are lists, tuples, and strings. By splitting another sequence, you can create a new sequence. The following features use lists as examples, but they can also be used for other sequence types such as tuples, strings, and bytes.
> > a = [0,2,4,6,8 Using a range 10,12,14,16,18,20] > # Using a range, [start, end) > > a [1:3] [2,4] > > # Using a range with a step > a [1:9:2] [2,6,10,14] > > # Leave out the start = an implicit start of 0 > > a [: 5] [0,2,4,6,8] > > # Leave out the stop = an implict end to the very last item > a [9:] [18 20] > > # Entire list > > a [:] [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20] Thank you for reading this article carefully I hope the article "how to divide the sequence of python" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!