[Tutor] string reversal using [::-1]
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Jun 10 19:37:53 EDT 2017
On 10/06/17 17:39, Vikas YADAV wrote:
> Question: Why does "123"[::-1] result in "321"?
>
> MY thinking is [::-1] is same as [0:3:-1], that the empty places defaults to
> start and end index of the string object.
Did you try that? You may be surprised.
The wonderful thing about the >>> prompt is that it's as quick
to try it out as to guess.
Look in the archives for a recent post by Steven(29/5,
"Counting a string backwards") that explains slicing,
it may help.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list