Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slice syntax #54

Merged
merged 2 commits into from
Dec 4, 2024
Merged

Add slice syntax #54

merged 2 commits into from
Dec 4, 2024

Conversation

tanyanliang110
Copy link
Contributor

@tanyanliang110 tanyanliang110 commented Nov 29, 2024

添加切片操作的语法 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]

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

netlify bot commented Nov 29, 2024

Deploy Preview for phenomenal-palmier-a1e093 failed.

Name Link
🔨 Latest commit 13cc016
🔍 Latest deploy log https://app.netlify.com/sites/phenomenal-palmier-a1e093/deploys/674e9a6b48e141000892fbfb

@tanyanliang110 tanyanliang110 changed the title 添加切片语法 Add slice syntax Dec 3, 2024
@guance-review-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tanyanliang110, vircoys

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vircoys vircoys merged commit f84a9b0 into GuanceCloud:main Dec 4, 2024
0 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants