1.4 反斜杠的倔强: 不写最后 ========================== .. image:: http://image.iswbm.com/20200804124133.png ``\`` 在 Python 中的用法主要有两种 **1、在行尾时,用做续行符** .. code:: python [root@localhost ~]$ cat demo.py print("hello "\ "world") [root@localhost ~]$ [root@localhost ~]$ python demo.py hello world **2、在字符串中,用做转义字符,可以将普通字符转化为有特殊含义的字符。** .. code:: python >>> str1='\nhello'  #换行 >>> print(str1) hello >>> str2='\thello'  #tab >>> print(str2) hello 但是如果你用单\ ``\``\ 结尾是会报语法错误的 .. code:: python >>> str3="\" File "", line 1 str3="\" ^ SyntaxError: EOL while scanning string literal 就算你指定它是个 raw 字符串,也不行。 .. code:: python >>> str3=r"\" File "", line 1 str3=r"\" ^ SyntaxError: EOL while scanning string literal