转义python字符串中的双引号 [英] escaping the double quotes in python string
本文介绍了转义python字符串中的双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于以Python字符串格式转义双引号的问题.例如
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
当我放5"6"时,它返回'5 \'6',但我不知道为什么会有反斜杠.
when I put 5" 6' , it returns ' 5\'6" ' and i don't get why there is a backslash.
推荐答案
您正在要求字符串的表示形式.由于字符串包含两种类型的引号,因此必须转义一种类型的 才能使其正确表示.如果只想输入,则使用%s
.
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.
这篇关于转义python字符串中的双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文