Slice confusion : a[n:p] is a list exclude the last element p

Terry Reedy tjreedy at udel.edu
Mon Apr 28 13:04:45 EDT 2003


"nguyen khanh" <phuoc-khanh.nguyen at bull.net> wrote in message
news:mailman.1051532982.25352.python-list at python.org...
>a=range(10)
>b=a[3:7]
>b=[3,4,5,6]
>Why the design exclude the last element ?

Think of slice coordinates as vertical bar cursor coordinates that
indicate positions before, between, and after the items of the
sequence.  n items gives n+1 cursor positions.  A slice indicates the
items between the cursor positions.

Terry








More information about the Python-list mailing list