What does "::" mean?
Robert Kern
rkern at ucsd.edu
Tue Jul 19 21:01:56 EDT 2005
could ildg wrote:
> I know that ":" can do slice works.
> But I saw "::" today and it puzzled me much,
> I can't find it in the python doc,
> so I raise this question here.
> The code is as below:
> ----------------------------------------------------------
> Jython 2.2a1 on java1.5.0_03 (JIT: null)
> Type "copyright", "credits" or "license" for more information.
>
>>>>live='live';print live
>
> live
>
>>>>live=live[::-1];print live
>
> evil
>
> --------------------------------------------------------
> "[::-1]" can reverse a string magicly, how did it do it?
The full form would be live[len(live)-1:-1:-1] much like
range(len(live)-1, -1, -1).
[start:stop:step]
step can be negative.
--
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