Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
引用 GuanceCloud/platypus#54 (comment)
添加切片操作的语法 a[start:end:step]支持字符串或数组切片,功能包括正向切片、反向切片、嵌套切片、负数索引等。
1.语法解释:
a :要进行切片操作的数组或字符串;
start:切片的起始索引(包含)。如果省略并且step>0,默认为 0;如果step<0,默认为字符串或数组的长度-1。
end:切片的结束索引(不包含)。如果省略并且step>0,默认为字符串或数组的长度,如果step<0,默认为数组或字符串的起始位置。
step:切片的步长。如果省略,默认为 1。
2.特殊处理:
①负数索引:允许从数组的末尾开始计数,索引从 -1 开始;
②允许索引超出范围,当切片的起始/结束位置超出列表的长度时,自动设置为字符串或数组的第一个元素/最后一个元素。
例如数组a=[]int{1,2,3,4,5}
a[-10:10]处理为a[0:5],a[10:-10:-1]处理为a[4::-1]