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...")

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.