#Beginner Question Slice Defaults

12 messages · Page 1 of 1 (latest)

worn sluice
#

Could anyone explain the 2nd and 3rd print statement to me please? I'm getting different numbers.

#

the default for low in the 2nd one should be 0? so it is the same as s = s[0:2] which should print 2, 3?

#

the 3rd one uses the default for high which is the length of the array? making it the same as s = s[1:6] which should print 3, 5, 7, 11, 13?

lime leaf
worn sluice
#

ah so every time there's a change I have to use the latest "iterration" of s

#

and then go from there

lime leaf
#

what you have to do depends on what you want to happen
slices are values, s[1:4] creates a new slice, assigning it to s means s has a different value now

#

more specifically, a slice is modeled as go type slice struct { ptr *T len, cap int }

#

where ptr points to the first entry (that this slice can see) of the underlying array

#

s[1:4] creates a new slice that "points to 3"

worn sluice
#

ah, that makes sense, getting the same numbers now

#

thank you very much