mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 23:08:34 +08:00
Update 07.2.md (#540)
s := [3]int{1,2,3}[:] 会导致panic: invalid operation [3]int literal[:] (slice of unaddressable value)
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
|
||||
如果你想去掉 slice1 的最后一个元素,只要 `slice1 = slice1[:len(slice1)-1]`。
|
||||
|
||||
一个由数字 1、2、3 组成的切片可以这么生成:`s := [3]int{1,2,3}[:]` 甚至更简单的 `s := []int{1,2,3}`。
|
||||
一个由数字 1、2、3 组成的切片可以这么生成:`s := [3]int{1,2,3}[:]`(注: 应先用`s := [3]int{1, 2, 3}`生成数组, 再使用`s[:]`转成切片) 甚至更简单的 `s := []int{1,2,3}`。
|
||||
|
||||
`s2 := s[:]` 是用切片组成的切片,拥有相同的元素,但是仍然指向相同的相关数组。
|
||||
|
||||
|
Reference in New Issue
Block a user