Hexadecimal and byte strings

Python functions are compiled to byte code which are represented as byte strings.

How did the byte string get converted to integers? Let's take it apart.

Each byte has a character (string) representation. The non-printing characters, like 0 and 1, are given by their corresponding hexadecimal character code, which uses the prefix '\x' to indicate that the next two characters are to be interpreted as hexadecimal.

We can convert decimal numbers to hexadecimal using the hex() function.

Thus, the ASCII code for 'd' is decimal 100, which is hexadecimal 0x64 (64).

The character for code 100 is 'd'. The ASCII code for '\x64' is 'd' as well.

In hexadecimal, 0x64 is an integer and '\x64' is a character.

The bytes() function converts strings to byte strings. See Byte sequence types.

See also Python encodings guide