Python escape characters are described in detail

  • 2020-05-27 06:01:28
  • OfStack

Python escape character

python USES a backslash (\) to escape characters when special characters need to be used in characters. The following table:

Original string

Sometimes we don't want the escape character to work, we just want to show the original meaning of the string, so we define the original string using r and R. Such as:

print r'\t\r'

The actual output is

 " \t\r " 

转义字符 描述
\(在行尾时) 续行符
\\ 反斜杠符号
\' 单引号
\" 双引号
\a 响铃
\b 退格(Backspace)
\e 转义
\n 换行
\v 纵向制表符
\t 横向制表符
\r 回车
\f 换页
\oyy 8进制数yy代表的字符,例如:\o12代表换行
\xyy 10进制数yy代表的字符,例如:\x0a代表换行
\other 其它的字符以普通格式输出

Thank you for reading, I hope to help you, thank you for your support of this site!

Related articles: