typora/note/Python/转义字符.md
2024-12-12 10:48:55 +08:00

17 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

| 转义字符 | 描述 | 实例 |
| :---------- | :----------------------------------------------------------- | :----------------------------------------------------------- |
| \(在行尾时) | 续行符 | >>> print("line1 \<br/>... line2 \<br/>... line3")<br/>line1 line2 line3<br/>>>> |
| | 反斜杠符号 | >>> print("\\")<br/>\ |
| \' | 单引号 | >>> print('\'')<br/>' |
| \" | 双引号 | >>> print("\"")<br/>" |
| \a | 响铃 | >>> print("\a") |
| \b | 退格(Backspace) | >>> print("Hello \b World!")<br/>Hello World! |
| \000 | 空 | >>> print("\000")<br/><br/>>>> |
| \n | 换行 | >>> print("\n")<br/><br/><br/>>>> |
| \v | 纵向制表符 | >>> print("Hello \v World!")<br/>Hello <br/> World!<br/>>>> |
| \t | 横向制表符 | >>> print("Hello \t World!")<br/>Hello World!<br/>>>> |
| \r | 回车,将 \r 后面的内容移到字符串开头,并逐一替换开头部分的字符,直至将 \r 后面的内容完全替换完成。 | >>> print("Hello\rWor!")<br/>Wor!o<br/> >>> print('google w3cschool taobao\r123456')<br/>123456 w3cschool taobao |
| \f | 换页 | >>> print("Hello \f World!")<br/>Hello <br/> World!<br/>>>> |
| \yyy | 八进制数y 代表 0~7 的字符,例如:\012 代表换行。 | >>> print("\110\145\154\154\157\40\127\157\162\154\144\41")<br/>Hello World! |
| \xyy | 十六进制数,以 \x 开头y 代表的字符,例如:\x0a 代表换行 | >>> print("\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21")<br/>Hello World! |
| \other | 其它的字符以普通格式输出 | |