一、删除单个元素
func main() {
seq := []string{"a", "b", "c", "d", "e"}
// 指定删除位置
index := 2
// 将删除点前后的元素连接起来
seq = append(seq[:index], seq[index+1:]...)
(seq)//[a b d e]
}
append的第二个参数是追加的元素,是一个一个的追加
如果第二个参数是slice,那么要用...,这样就会把第二个slice中的元素一个一个的追加到第一个slice中
二、批量删除
删除前4个元素
func main() {
seq := []string{"a", "b", "c", "d", "e"}
// 指定删除位置
index := 3
// 将删除点前后的元素连接起来
seq = append(seq[:0], seq[index+1:]...)
(seq)//[e]
}