Home  >  Article  >  Backend Development  >  What is python slicing?

What is python slicing?

藏色散人
藏色散人Original
2019-07-02 11:23:2412653browse

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

What is python slicing?

The above means intercepting the characters wangl

What is python slicing?

2 Advanced

(1) Step size

The above is the basic usage, the step size means intercepting every few digits

, such as:

What is python slicing?

The intercepted string should be wnl

What is python slicing?

(2) Usage of -1

In the slice, -1 represents the meaning of the last digit

For example,

What is python slicing?

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

What is python slicing?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn