Python反斜杠后跟数字

2024-06-16 10:46:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python中转义键的理解如下:

They can be used to represent special characters (tab "\t", newline "\n", vertical indent "\v")

They can negate quotes/apostrophes ("\"", '\'')

They can negate the backslash escape key ('\\')

但是为什么'\1\2\3\4\5\6'显示为☺☻♥♦♣♠

为什么'\7'在我的电脑上发出噪音

为什么任何大于7的数字都不适用于逃生键?例如print('\8')显示为:\8


Tags: tonewlinebetabcanquotesusedspecial
1条回答
网友
1楼 · 发布于 2024-06-16 10:46:48

The \000 escape code produces the ASCII character with that octal value, ASCII 1 is Control-A, ASCII 7 is Control-G, which is the bell. \015 is Ctrl-M, carriage return. \012 is Ctrl-J, line feed. It's exactly like \x07, except octal instead of hexadecimal. All of this was inherited from C.

通过{a2}

相关问题 更多 >