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

后端 未结 12 1417
后悔当初
后悔当初 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:24

    In order for you to end a raw string with a slash I suggest you can use this trick:

    >>> print r"c:\test"'\\'
    test\
    

提交回复
热议问题