How to Create and Initialize a Slice in Go

Create a Go slice using the make function for specific capacity or slice literals for immediate values.

Use the make function to create a slice with a specific length and capacity, or the slice literal syntax for immediate initialization.

// Create empty slice with length 3 and capacity 5
s1 := make([]int, 3, 5)

// Create slice initialized with values
s2 := []int{1, 2, 3}

// Create empty slice (length 0, capacity 0)
s3 := []int{}