Hello, When you use the colon, you taking a subset of the data. Further, the notation is a closed/open. So a slice primes[6:6] is all of the element in the array with index >= 6 and index < 6, which is an empty set. Note that the type of the expression primes[6:6] is []int.
When you don't use the colon, you are access a specific element. Since the count is zero based, the valid indices are 0 through 5 inclusive. Note that the type of the expression primes[6] is simply int. Good luck. On Thursday, 7 March 2019 10:32:04 UTC-5, Halbert.Collier Liu wrote: > > Hi. > > The code like below: > > package main > > import "fmt" > > func main() { > primes := [6]int{2, 3, 5, 7, 11, 13} > fmt.Println(primes[6:6]) . // *OK*. return: [] > //fmt.Println(primes[6]) . // fail. out of bounds... > } > > Why? > > Is the golang grammatical feature? or anything else.. > > Any help, please! > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.