Home > Article > Backend Development > What is python slicing?
What is python slice?
Slicing refers to the concept of taking out a part of the operation object
Strings, lists, and tuples all support slicing syntax
The syntax of slicing is [ Start : End : Step size]
Note here: the selected interval is closed on the left and open on the right, that is, including the starting position and excluding the ending position
1 String slice
The above means intercepting the characters wangl
2 Advanced
(1) Step size
The above is the basic usage, the step size means intercepting every few digits
, such as:
The intercepted string should be wnl
(2) Usage of -1
In the slice, -1 represents the meaning of the last digit
For example,
The intercepted string should be wnl. Why is it not obtained? Because -1 represents the last digit, which is the sixth digit, but the slice area is Left closed and right open. So i
is not included. Related recommendations: "Python Tutorial"
The above is the detailed content of What is python slicing?. For more information, please follow other related articles on the PHP Chinese website!