The "colon" [:] In the Python data type -- slice and step size operation example,
The example in this article describes the "colon" [:] In the Python data type -- multipart and step size operations. We will share this with you for your reference. The details are as follows:
For example, the following string is available:
String = "welcome to jb51 ^_^"
You can use the part character and step character to split the string and define the step size.
String = "welcome to jb51 ^_^" # All print string [:] # results from 1 to 9 are returned by default. print string [] # results from 1 to 9 are returned, the step size is 1 print string [1: 9:] # returns the results from 1 to 9. The step size is 2 print string [] # returns the results from 1 to 9, the step size is-1 print string [1: 9:-1] # transpose print string [:-1]
The result is as follows:
Found here
# Return the results from 1 to 9. The step size is-1 print string [1: 9:-1]
No reverse order from 1 to 9 is output.String [1: 9]As the first string, and then transposed.
# Return the results from 1 to 9. The step size is-1 print string [] [:-1].
It is very spiritual to use this method to determine whether the substring of a string is a text string.
Note:Target ImageString [start: end: step]When the step is positive, start must be smaller than end. If the step is negative, start must be greater than end.