在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是否有类似于第二个和第三个示例的快捷方式?
发布于 2016-05-20 22:45:06
不,你必须使用len(a)。
a[len(a)-1]
a[len(a)-2:]
a[:len(a)-2]https://stackoverflow.com/questions/37356892
复制相似问题