append golang example
package main
import (
"fmt"
)
func main() {
slice := []int{1, 2, 3, 4, 5}
slice = append(slice, 6, 7, 8)
fmt.Println(slice)
}
The append
function in Go is used to add elements to a slice. In this example, a slice of integers is created with values 1, 2, 3, 4, and 5. The append
function is then used to add 6, 7, and 8 to the slice. Finally, the modified slice is printed to the console.