Answer the question
In order to leave comments, you need to log in
Why can foo[len(foo):]?
foo := [5]int{0, 1, 2, 3, 4}
fmt.Println(foo[:5]) //так можно
fmt.Println(foo[5:]) //и так
fmt.Println(foo[5]) //так нет. Почему?
//Где это документировано? Как это понимать
Answer the question
In order to leave comments, you need to log in
You are wrong about the lack of documentation on this topic
a[2:] // same as a[2 : len(a)]
a[:3] // same as a[0 : 3]
a[:] // same as a[0 : len(a)]
Because this is a call to a non-existent 5th element in the array. Addressing starts at index 0 and the element with index 4 is the last one in it.
The first border is included in the slice; the latter is not included, so we write - this is an empty slice, you can also get it like this:
or like this:foo[5]
fmt.Println(foo[1:1])
Be inspired by everything, but not by other people's interfaces, because it will be just copying. This is a dead end development.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question