Concantenation and string slicing
Larry Bates
larry.bates at websafe.com
Thu Feb 23 19:06:46 EST 2006
DannyB wrote:
> I've written a program that takes a phrase and spits it back out
> backwards. My problem is it throws each character on a new line. I'd
> like the phrase to be on the same line. Is this possible?
>
> #Backward Message
>
> message = raw_input("Enter a message: ")
> letter = len(message)
> while (letter > 0):
> newMessage = ""
> newMessage += message[letter-1]
> letter -= 1
> print newMessage
>
>
> Thanks!!
>
> Dan
>
Better was is:
message = raw_input("Enter a message: ")
print message[::-1]
-Larry Bates
More information about the Python-list
mailing list