Search code examples
pythonforwardslashraw-input

How to get rid of forward slash in Python raw_input()


Beginner programmer here. So bear with me. I have a simple python program.

print "How tall are you?",
height = raw_input()

print "So you're %r tall" %(height)

If I enter the height as 6'6'' python would output

So you're '6\6"'

How do I get rid of the forward slash "\" from the output?

Thanks in advance!


Solution

  • %r converts to the repr of height, you should use %s instead

    If you are using Python >=2.6, you can write it this way instead

    print "So you're {height} tall.".format(height=height)