Yes, i see, 
thank you so much!

Could you please explain, why primes[6:6] okay, but primes[7:7] not?


在 2019年3月7日星期四 UTC+8下午11:55:29,Burak Serdar写道:
>
> On Thu, Mar 7, 2019 at 8:31 AM <halbert...@gmail.com <javascript:>> 
> 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? 
>
> Those two expressions are doing different things: 
>
> primes[6:6] is a slice that begins after the last element of primes, 
> with len=0. You can, for instance, add a new element to primes[6:6], 
> which makes a new slice with one element. primes[6:7], for instance, 
> would be an error, 
>
> primes[6] is an int, accessing the element beyond array bounds, so it 
> is an error. 
>
> > 
> > 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.

Reply via email to