escaping the double quotes in python string

左心房为你撑大大i 提交于 2021-01-29 15:50:54

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8276820/escaping-the-double-quotes-in-python-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!