Go编程语言切片从头开始

Go programming language slice from end

在 python 中,您可以使用以下语法作为快捷方式:

a[-1]    # last item in the array
a[-2:]   # last two items in the array
a[:-2]   # everything except the last two items

Go在创建新切片时是否有类似于第二个和第三个示例的快捷方式?

不,你必须使用 len(a)

a[len(a)-1]
a[len(a)-2:]
a[:len(a)-2]