slice [ ]
Try it yourself →List of dynamic length.
Syntax
name := []type{e1, e2, ...}Description
Slices are the most commonly used in Go (arrays have a fixed size). Elements are accessed by index starting from 0.
Example
package main
import "fmt"
func main() {
colors := []string{"red", "purple"}
fmt.Println(colors[0])
fmt.Println(len(colors))
}Expected output
red 2
When to use?
Storing lists.