Go 中切片索引与 Python 中列表索引的差异
发布日期:2021-05-10 08:44:32 浏览次数:17 分类:精选文章

本文共 3833 字,大约阅读时间需要 12 分钟。

���������������������������������������������������������

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

Python ������������������

��� Python ���������������������������������������������������������������������

  • ������������������������������������

    ��������������� Python ���������������������������������������������������������������������������������

    a = [1, 2, 3, 4, 5, 6, 7]
    a[0:10] # ������������������������������ 0:10 ������������������

    ��������� a[0:10] ������������������������������ [1, 2, 3, 4, 5, 6, 7]���������������������������������������������������������������������������������������������������������������

  • ������������������������

    ��� Python ���������������������������������������������������������������������������

    a = [1, 2, 3, 4, 5, 6, 7]
    a[5:-1] # ��������������� 5 ��������������� 6���������������������������������������
    # ������ [6]
    a[3:-1] # ��������� 3 ���������������������������������������������
    # ������ [4, 5]

    ������������������������������������������������������������������������������������������

  • Go ������������������������

    ��� Python ���������Go ���������������������������������������������������������������������������������������������������������������������������������

  • ������������������������������������

    ��� Go ���������������������������������������������������������������������������������������������������������������������������������

    package main
    import "fmt"
    func main() {
    s3 := []int{1, 2, 3, 4, 5, 6, 7, 8}
    // ���������������������������������������������������������������������
    s7 := s3[0:10]
    fmt.Printf("The value of s7: %#v\n", s7)
    }

    ��������������������������� s3[0:10] ��������� panic: runtime error: slice bounds out of range ��������������������������������� 8 ������������������������ 10 ������������������

  • ������������������������

    Go ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

  • ���������������������������������

    ������������������������������Python ������������������������ Go ���������������������������������������������������������������������������������������������������

  • Python ������������

    Python ���������������������Developer ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

  • Go ������������

    Go ��������������������������������������������������������������������������������������������������������������������������������������������������� crash������������������������������������������������������������������������������������������������������������������������������

  • ������������������

    ������������������������������������������������������������������������������������������������������������Python ��������� Go ������������������������������������������������������������Go ���������������������������

    • ������ Python ���������

      • ������������������
      • Web ������������
      • ���������������������������������������
    • ������ Go ���������

      • ������������������������
      • ������������������������������������
      • ���������������������������������

    ������

    ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:fatal error all goroutines are asleep - deadlock!
    下一篇:Golang 元素值在经过通道传递时会被复制,这个复制是浅复制

    发表评论

    最新留言

    路过按个爪印,很不错,赞一个!
    [***.219.124.196]2025年04月27日 18时02分27秒