[Tutor] how to print a message backwards

Robert Berman bermanrl at cfl.rr.com
Wed Sep 23 20:10:44 CEST 2009


Is there a significant difference in speed, style, or any pythonesque
reasoning between Alan's solution and 
print message[::-1]

Thanks for any information,

Robert


On Wed, 2009-09-23 at 18:51 +0100, Alan Gauld wrote:
> "Ali Sina" <seena_blk at yahoo.com> wrote 
> 
> #Message backward printer
> message=input('Enter your message: ')
> 
> for i in range(len(message),0,-1):
> print(message)
> 
> 
> > This is the code which I have written. 
> > All it does is count the number of letters starting from backwards. 
> 
> Correct, plus it prints the original message each time.
> So obviously you need to print something else! If you are counting 
> one letter at a time maybe you should print one letter at a time?
> 
> However/...
> Others have given you a big hint about using slicing instead 
> so I'll leave you to research that yourself.
> 
> 



More information about the Tutor mailing list