What does "::" mean?

Robert Kern rkern at ucsd.edu
Wed Jul 20 17:20:01 EDT 2005


Rob Williscroft wrote:

> import sys
> 
> live = 'live'
> 
> print live[ sys.maxint  :              : -1 ]
> print live[ len(live)-1 :              : -1 ]
> 
> print live[ len(live)-1 : -len(live)-1 : -1 ]
> print live[ len(live)-1 : -sys.maxint  : -1 ]
> print live[ sys.maxint  : -sys.maxint  : -1 ]
> print live[ -1          : -len(live)-1 : -1 ]
> 
> Of course there is only one obvious way to do it, but alas
> as I'm not Dutch I can't tell which it is.

Well, that part's easy at least:

   live[::-1]

:-)  And so the circle is complete ...

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list