美文网首页Python3
Python list negative index

Python list negative index

作者: JaedenKil | 来源:发表于2019-01-15 17:03 被阅读5次
    """
    Negative index means count backwards.
    Counting backwards begins with "-1", while counting forwards begins with "0"
    """
    
    a = [1, 2, 3]
    print(a[-1])  # 3
    print(a[-2])  # 2
    print(a[0])  # 1
    

    相关文章

      网友评论

        本文标题:Python list negative index

        本文链接:https://www.haomeiwen.com/subject/savydqtx.html