0

What's the command that allows you to do that. The chapter that i'm reading lists slicing, but I don't see how that helps if you don't have a fixed value of the word.

# Program that gets a message from user and computer prints it out backward.

message = raw_input ("Enter any message...")
2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by dseto200
0

Use the slicing operators defaults and -1 as the step ...

# slicing operator seq[begin : end : step]
# defaults are index begin=0,  index end=len(seq)-1,  step=1
# -begin or -end --> count from the end backwards
# step = -1 reverses sequence

message = raw_input ("Enter any message...")[::-1]
print message
0

Thanks Vegaseat learn more from this forum than the python book that i'm reading.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.