ref: 2f386b7b411c6fb68748e0a266616efb01675109 a-tour-of-go/basics/structs-slices-maps/1.3.7_slices.go -rw-r--r-- 539 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
	Notes 1.3.6

	- A slice is a dynamically-sized, flexible view into the elements of an array
	- Slices are more common than arrays in practice
	- Specify a slice like this: a[low : high]
		It excludes the end (high)
	- The difference between arrays and slices when declared are subtle;
	  if there is a size specified, it's an array. 
*/

package main

import "fmt"

func main() {
	primes := [6]int{2, 3, 5, 7 , 11, 13}	// This is an array

	var s []int = primes[1:4]	// This is a slice. Selects [3, 5, 7] from primes.
	fmt.Println(s)
}