第十七十八章 (#833)

Co-authored-by: Joe Chen <jc@unknwon.io>
This commit is contained in:
Haigang Zhou
2022-05-19 19:57:23 +08:00
committed by GitHub
parent 72bc74ab95
commit fa1cfcc67f
12 changed files with 66 additions and 67 deletions

View File

@@ -1,22 +1,22 @@
# 18.2 数组和切片
创建:
- 创建:
`arr1 := new([len]type)`
`arr1 := new([len]type)`
`slice1 := make([]type, len)`
`slice1 := make([]type, len)`
初始化:
- 初始化:
`arr1 := [...]type{i1, i2, i3, i4, i5}`
`arr1 := [...]type{i1, i2, i3, i4, i5}`
`arrKeyValue := [len]type{i1: val1, i2: val2}`
`arrKeyValue := [len]type{i1: val1, i2: val2}`
`var slice1 []type = arr1[start:end]`
`var slice1 []type = arr1[start:end]`
1如何截断数组或者切片的最后一个元素
`line = line[:len(line)-1]`
`line = line[:len(line)-1]`
2如何使用 `for` 或者 `for-range` 遍历一个数组(或者切片):