I can't seem to wrap my head around the notation of indices when working with Go slices.
Given a slice s
.
s := []int{1, 2, 3, 4, 5}
I now want to create a new slice s2 = [2 3]
.
s2 := s[1:3] // s2 = [2 3]
Now, what is the thought process that I should go through when accessing this value? Am I reading values starting from index 1
up to and including the third element of the slice? Or am I reading values from index 1
up to and excluding index 3
?
I am not starting at index 1
and going up to index 3
and neither am I starting at position 1
and going up to position 3
as both of these would result in s2
having 3 elements.
What is the idea behind this notation?