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

Question:

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

Asked By: Haiyuan Zhang

||

Answers:

That’s unicode character escaping. See “Unicode Constructors” on PEP 100

Answered By: Jake Wharton

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.

Answered By: Alex Martelli
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.