Python Literal r'\' Not Accepted

前端 未结 5 2107
感情败类
感情败类 2021-01-17 08:25

r\'\\\' in Python does not work as expected. Instead of returning a string with one character (a backslash) in it, it raises a SyntaxError. r\"\\\"

5条回答
  •  不要未来只要你来
    2021-01-17 08:48

    That is because in raw strings, you need a way to escape single quotes when the string is delimited by single quotes. Same with double quotes.

    http://docs.python.org/reference/lexical_analysis.html#string-literals

提交回复
热议问题