Why can't Python's raw string literals end with a single backslash?

后端 未结 12 1412
后悔当初
后悔当初 2020-11-22 07:37

Technically, any odd number of backslashes, as described in the documentation.

>>> r\'\\\'
  File \"\", line 1
    r\'\\\'
       ^
Syn         


        
12条回答
  •  庸人自扰
    2020-11-22 08:22

    Since \" is allowed inside the raw string. Then it can't be used to identify the end of the string literal.

    Why not stop parsing the string literal when you encounter the first "?

    If that was the case, then \" wouldn't be allowed inside the string literal. But it is.

提交回复
热议问题