Go · Stage 5 – Grouping Data · Lesson 31 of 64

Slices

Use Go’s flexible view over a sequence and distinguish it from an array.

Go code

names := []string{"Maya", "Noah"}
fmt.Println(names)
Line-by-line explanation
  1. Empty square brackets mean slice rather than fixed array.
  2. String is the item type.
  3. The values initialize the slice.
Expected output
[Maya Noah]

This is the expected result.

A slice stores a small description pointing to an underlying array. It has a length and a capacity. You usually work with slices in everyday Go.