[Tutor] how to print a message backwards
Sander Sweers
sander.sweers at gmail.com
Thu Sep 24 13:05:41 CEST 2009
2009/9/24 ALAN GAULD <alan.gauld at btinternet.com>:
>> print message[::-1]
>
> Yes, the for loop doing one character at a time will be much
> slower than using a slice. The slice is more pythonic but less general.
> A reverse loop is something that is often needed in programming
> solutions so it's useful to know how to do it for the general case.
I have seen this some times but never really understood how it worked.
I have 1 thing I am not sure of, the negative slice in the example
basically means "start counting at the end position and work
backwards"?
Does anyone have an advanced topic on slicing where the :: notation is
explained?
Thanks
Sander
More information about the Tutor
mailing list