Create a slice with a literal:
nums := []int{1, 2, 3, 4, 5}
names := []string{"Alice", "Bob"}
This creates a slice and an underlying array to hold the values. The slice has length equal to the number of elements provided.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Direct initialization
Create a slice with a literal:
nums := []int{1, 2, 3, 4, 5}
names := []string{"Alice", "Bob"}
This creates a slice and an underlying array to hold the values. The slice has length equal to the number of elements provided.