Use make to create a slice with specified length:
nums := make([]int, 5)
This creates a slice of length , all zeros. You can also specify capacity:
nums := make([]int, 5, 10)
Length , capacity . The extra capacity allows growth without reallocation.