Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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).


Yes, I was the one who made the comment about Go's lack of a -1 for slices in the first place. ;)

I was actually referencing the 0 part and thus saying Go does already have some syntactic sugar when dealing with slices. ie you can do:

   slice[5:]   // slice[:len(slice)]
but not

   slice[5:-1] // slice[:len(slice)-1]
Which is a great pity.

However I'll update my previous comment to make that clearer because I can totally understand how it reads confusingly.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: