Colon (:) in Python list index

This question already has an answer here:

  • Understanding Python's slice notation 29 answers

  • : is the delimiter of the slice syntax to 'slice out' sub-parts in sequences , [start:end]

    [1:5] is equivalent to "from 1 to 5" (5 not included)
    [1:] is equivalent to "1 to end"
    [len(a):] is equivalent to "from length of a to end"
    

    Watch https://youtu.be/tKTZoB2Vjuk?t=41m40s at around 40:00 he starts explaining that.

    Works with tuples, dictionaries and lists, too.


    slicing operator. http://docs.python.org/tutorial/introduction.html#strings and scroll down a bit


    a[len(a):] - This gets you the length of a to the end. It selects a range. If you reverse a[:len(a)] it will get you the beginning to whatever is len(a) .

    链接地址: http://www.djcxy.com/p/26728.html

    上一篇: 否定列表索引?

    下一篇: 在Python列表索引中的冒号(:)