For a few characters in a string, different languages have different solutions, and Python has a way of slicing.
In the list, the following:
S=list (range (1,101))
If you want to pick an even number of numbers (or select even), you can use the Loop method: But the method is bloated, compared to "stupid"
But the slicing method given in Python is more elegant, as follows:
L=list (range (1,101)) print (l[0]) print (l[0:10]) #输出结果是 [1, 2, 3, 4, 5, 6, 7, 8, 9, +] print (L[1:3]) #输出的结果是 [ 2,3]
When the parameter is only two, the parameter preceding the colon is the index value of the start character, and the argument after the colon is the index value of the ending character. Note that the output here is a character that does not contain the following index value.
When there are three parameters, the last parameter x indicates that one character is selected every x.
Example:
Print (L[4:50:5])
The output is a multiple of five.
Of course, the parameter can also be negative, indicating the number of countdown
Also, it can be omitted when the parameter is 0.
Slicing issues in Python