提交 047c6426 编写于 作者: 彭世瑜's avatar 彭世瑜

fix

上级 efcf9fc3
......@@ -90,3 +90,67 @@ func main() {
}
```
## 切片初始化
直接初始化
```go
s := []int{1, 2, 3, 4, 5}
fmt.Printf("s: %v\n", s)
// s: [1 2 3 4 5]
```
使用数组初始化
```go
arr := [...]int{1, 2, 3, 4, 5}
s := arr[:]
fmt.Printf("s: %v\n", s)
// s: [1 2 3 4 5]
```
空切片
```go
var s []int
```
切片操作
```go
package main
import (
"fmt"
)
func main() {
s := []int{1, 2, 3, 4, 5}
fmt.Printf("s: %v\n", s)
// s: [1 2 3 4 5]
// [0, 3)
s1 := s[0:3]
fmt.Printf("s1: %v\n", s1)
// s1: [1 2 3]
// [3, 最后)
s2 := s[3:]
fmt.Printf("s2: %v\n", s2)
// s2: [4 5]
// [开始,3)
s3 := s[:3]
fmt.Printf("s3: %v\n", s3)
// s3: [1 2 3]
// 拷贝
s4 := s[:]
fmt.Printf("s4: %v\n", s4)
// s4: [1 2 3 4 5]
}
```
\ No newline at end of file
......@@ -39,4 +39,5 @@ https://www.bilibili.com/video/BV1ME411Y71o?p=27&spm_id_from=pageDriver&vd_sourc
https://www.bilibili.com/video/BV1zR4y1t7Wj?p=32&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da
\ No newline at end of file
https://www.bilibili.com/video/BV1zR4y1t7Wj?p=33&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册