[Tutor] Array slices in python with negative step

vishwajeet singh dextrous85 at gmail.com
Mon Jan 11 17:20:10 CET 2010

Hello All,

I am bit confuse how the slice works in case a negative step is supplied
a = 'abcde'
a[::-1] gives me edcba

but [4:0:-1] gives me edcb

while searching net I came accross something which said the following:

If a negative stride is specified and the starting or stopping indices are
omitted, they default to ``end of axis'' and ``beginning of axis''
In my case 4 is end of axis and 0 is begining of the axis so a[::-1] should
be equivalent to [4:0:-1] but result which I get in both the cases does not

Vishwajeet Singh
+91-9657702154 | dextrous85 at gmail.com | http://singhvishwajeet.com
Twitter: http://twitter.com/vishwajeets | LinkedIn:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100111/0cc00530/attachment-0001.htm>

More information about the Tutor mailing list