slice3.goΒΆ

// slice3.go

// To run at the command line:
//    $ go run slice3.go

package main

import "fmt"

func main() {
    nums := []int{0, 1, 2, 3, 4, 5, 6, 7}

    left := nums[0:4]
    right := nums[4:]
    middle := nums[1 : len(nums)-1]

    fmt.Println("  nums: ", nums)
    fmt.Println("  left: ", left)
    fmt.Println(" right: ", right)
    fmt.Println("middle: ", middle)

    right[1] = -999

    fmt.Println()
    fmt.Println("  nums: ", nums)
    fmt.Println("  left: ", left)
    fmt.Println(" right: ", right)
    fmt.Println("middle: ", middle)
}