What does a leading `\x` mean in a Python string `\xaa`

后端 未结 2 1921
耶瑟儿~
耶瑟儿~ 2020-11-27 12:30

What is difference between \'aa\' and \'\\xaa\'? What does the \\x part mean? And which chapter of the Python documentation covers thi

相关标签:
2条回答
  • 2020-11-27 12:40

    That's unicode character escaping. See "Unicode Constructors" on PEP 100

    0 讨论(0)
  • 2020-11-27 12:55

    The leading \x escape sequence means the next two characters are interpreted as hex digits for the character code, so \xaa equals chr(0xaa), i.e., chr(16 * 10 + 10) -- a small raised lowercase 'a' character.

    Escape sequences are documented in a short table here in the Python docs.

    0 讨论(0)
提交回复
热议问题