删除切片中某一个元素
v1 := []int{1,2,3,4,5,6} deleteIndex := 2 // 切片获取到 {1,2,4、5、6} // 又获取到 [4,5,6},将4、5、6要追加到 result := append(v1[:deleteIndex], v1[deleteIndex+1:]...); fmt.Println(result) //{1,2,4,5,6} fmt.Println(v1) //{1,2,4,5,6,6}
循环
v1 = []int{1,2,3,4,5,6} for i:=0;i<len(v1);i++{ fmt.Println(i, v1[i]) } for index, value := range v1 { fmt.Println(index, value) }