Go slices store ordered values and work well with loops and indexing.

Slices

slices.go
package main

import "fmt"

func main() {
	var scores = 
	firstScore := scores[0]
	total := 0

	for _, score := range scores {
		total += score
	}

	average := total / len(scores)
	fmt.Println("first=", firstScore)
	fmt.Println("average=", average)
}
package main

import "fmt"

func main() {
	var scores = 
	firstScore := scores[0]
	total := 0

	for _, score := range scores {
		total += score
	}

	average := total / len(scores)
	fmt.Println("first=", firstScore)
	fmt.Println("average=", average)
}
package main

import "fmt"

func main() {
	var scores = 
	firstScore := scores[0]
	total := 0

	for _, score := range scores {
		total += score
	}

	average := total / len(scores)
	fmt.Println("first=", firstScore)
	fmt.Println("average=", average)
}
slice A slice is a flexible view over ordered values, written with syntax such as `[]int{1, 2, 3}`.