Ye Lin Aung
Ye Lin Aung

Reputation: 11469

escaping the double quotes in python string

I've a question about double quotes escaping in python string formatting. for example,

    print "How tall are you?",

    height = raw_input()

    print "So you are %r tall" % height

when I put 5" 6' , it returns ' 5\'6" ' and i don't get why there is a backslash.

Upvotes: 0

Views: 1186

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799420

You're asking for the representation of the string. Since the string contains both types of quotes, one type must be escaped in order for it to be a proper representation. If you only want what was typed then use %s instead.

Upvotes: 5

Related Questions