> Python supports slice[-1] for the last element... Pretty reasonable.
Lots of languages offer something akin to that. If not `[-1]` then something more OO like `.last`. Even the language I wrote supports it. This is why I made the complaint about Go.
> Also slice[0:-1] etc.
In fairness, Go can do that. You just omit the value for where you want the last (or first) element of the slice or array. eg
b := []byte("Hello, World")
world := b[7:]
(this would work with strings too but I'm using a byte to make it clear we're working with slices)
edit: just for clarity I mean Go has the syntactic sugar for stating the start or end of a slice - rather than a negative number of elements from the end of the slice. My point being that there is already some syntactic sugar in specifying slices so it's a shame Go doesn't take that further.
In python slice[0:-1] drops the last element. To get the same effect in Go you need world := b[:len(b)-1]. The len() needs to be there (your example is a different case).
Lots of languages offer something akin to that. If not `[-1]` then something more OO like `.last`. Even the language I wrote supports it. This is why I made the complaint about Go.
> Also slice[0:-1] etc.
In fairness, Go can do that. You just omit the value for where you want the last (or first) element of the slice or array. eg
(this would work with strings too but I'm using a byte to make it clear we're working with slices)edit: just for clarity I mean Go has the syntactic sugar for stating the start or end of a slice - rather than a negative number of elements from the end of the slice. My point being that there is already some syntactic sugar in specifying slices so it's a shame Go doesn't take that further.