Why Python does *SLICING* the way it does??

Sion Arrowsmith siona at chiark.greenend.org.uk
Wed Apr 20 09:10:03 EDT 2005


Raymond Hettinger <python at rcn.com> wrote:
><seberino at spawar.navy.mil>
>> Many people I know ask why Python does slicing the way it does.....
>Python's way has some useful properties:
>
>* s == s[:i] + s[i:]
>
>* len(s[i:j]) == j-i     # if s is long enough

The latter being particularly helpful when i = 0 -- the first n
elements are s[:n] . (Similarly elegantly, although of no
practical significance, s == s[0:len(s)] .)

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list