dsfh40613182 2016-05-20 22:43
浏览 37
已采纳

从头开始编程语言

In python you can use the following syntax as a shortcut:

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

Does Go have shortcuts similar to the second and third example when creating new slices?

  • 写回答

1条回答 默认 最新

  • dongpin4611 2016-05-20 22:45
    关注

    Nope, you have to use len(a).

    a[len(a)-1]
    a[len(a)-2:]
    a[:len(a)-2]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?