python raw字符串为什么不能以反斜杠结尾
1个回答
展开全部
这是一个Python语法解析中的瑕疵,没有办法解决,文档里已经明确说明不可以了
http://docs.python.org/reference/lexical_analysis.html
String quotes can be escaped with a backslash, but the backslash
remains in the string; for example, r"\"" is a valid string literal
consisting of two characters: a backslash and a double quote; r"\" is
not a valid string literal (even a raw string cannot end in an odd
number of backslashes). Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character).
Python这么设计大概是因为Python解释器对.py源文件的解析要求吧。
可以用 r'abc'+'\\' 的形式代替。
http://docs.python.org/reference/lexical_analysis.html
String quotes can be escaped with a backslash, but the backslash
remains in the string; for example, r"\"" is a valid string literal
consisting of two characters: a backslash and a double quote; r"\" is
not a valid string literal (even a raw string cannot end in an odd
number of backslashes). Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character).
Python这么设计大概是因为Python解释器对.py源文件的解析要求吧。
可以用 r'abc'+'\\' 的形式代替。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询