[Tutor] Array slices in python with negative step
Alan Gauld
alan.gauld at btinternet.com
Mon Jan 11 20:46:09 CET 2010
"vishwajeet singh" <dextrous85 at gmail.com> wrote
> Thanks for your response but I am still not clear; can you show me the
> equivalent of [::-1] in terms actually specifying start-index, end-index
> which gives me reverse of the given arrary.
I don't think you can, you must use the empty value.
In theory you could use -1 except of course -1 refers to the 'e'...
Its a slight anomoly due to the use of negative indexing. You
can do:
'abcde'[0:5]
and get the same as [0:]
But you cannot put any valid value for x in
'abcde[4 : x :-1]
that gets you the full string. You need to use [4::-1]
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list