Last item in a slice

To read the last element:

a := []string{"A", "B", "C"}
s := a[len(a)-1] // C

To remove it:

a = a[:len(a)-1] // [A B]

(Go doesn’t have negative indexing like Python does. This is a deliberate design decision — keeping the language simple can help save you from subtle bugs.)

Watch out for memory leaks

If the slice is permanent and the element temporary, you may want to remove the reference before removing the element from the slice.

a[len(a)-1] = "" // Erase element (write zero value)
a = a[:len(a)-1] // [A B]

Further reading

Slices in a nutshell