×

go · level 1 · unit 6 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A keeps many values together, in order.

A slice is a list of values kept in one box, in order, like a shopping list. snacks := []string{"crisps", "apple", "cake"} makes a slice of three strings.

[]string says the slice holds strings. A slice of whole numbers is []int. Each value in a slice is an , and every item must be the same type.

len(snacks) counts the items. fmt.Println(snacks) shows the whole slice inside square brackets, with spaces between the items.

package main
import "fmt"
func main() {
	snacks := []string{"crisps", "apple", "cake"}
	scores := []int{7, 9, 4}
	fmt.Println(snacks)
	fmt.Println(len(snacks), "snacks")
	fmt.Println(scores)
}

The items go inside curly brackets, with a comma between each one.