Why is '\x' invalid in Python? Why is '\x' invalid in Python? python python

Why is '\x' invalid in Python?


There is a table listing all the escape codes and their meanings in the documentation.

Escape Sequence    Meaning                        Notes\xhh               Character with hex value hh    (4,5)

Notes:

4. Unlike in Standard C, exactly two hex digits are required.
5. In a string literal, hexadecimal and octal escapes denote the byte with the given value; it is not necessary that the byte encodes a character in the source character set. In a Unicode literal, these escapes denote a Unicode character with the given value.


x is used to define (one byte) hexadecimal literals in strings, for example:

'\x61'

will evaluate to 'a', because 61 is the hexadecimal value of 97, which represents a in ASCII