Home  >  Article  >  Backend Development  >  What does a[1:] mean in Python?

What does a[1:] mean in Python?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-21 15:47:4018622browse

What does a[1:] mean in Python?

What does a[1:] mean in python? Here is a detailed introduction to you:

String interception, also called string slicing, uses square brackets [ ] to intercept strings. In Python, a single character is also used as a string.

String [start index: end index: step size]

Start index: start interception from the specified position;

End index: end interception from the specified position, but not Contains the characters at that position.

Step size: When not specified, the step size is 1;

String [start index: end index]

String interception follows the principle of "left closed and right opened", Also called "include left but not right"

Example:

>>> a=[1,2,3,4,5]
>>> print(a[1:])
[2, 3, 4, 5]
>>> a=(1,2,3,4,5)
>>> print(a[1:])
(2, 3, 4, 5)

a[1:]

a is a character String, 1 is the starting index, if the ending index is not specified, it defaults to the last digit. String interception follows the "left-closed, right-open" principle, that is, intercepting starts from 1, excluding 1, and intercepts to the last digit, including the last digit.

The above is the detailed content of What does a[1:] mean in Python?. 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