2024-04-25 07:21:13 发布
网友
考虑这行Python代码:
s = "This string has \n\r whitespace"
我该怎么做
print s
给我
This string has \n\r whitespace
而不是
This string has whitespace
就像现在一样。
您需要repr函数。
repr
print repr(s)
你想要一根生绳子吗?
s = r"This string has \n\r whitespace"
或者将特殊字符转换为它的表示形式?
repr(s)
print s.encode('string-escape')
您需要
repr
函数。你想要一根生绳子吗?
或者将特殊字符转换为它的表示形式?
相关问题 更多 >
编程相关推荐