I'm trying to understand the way Python displays strings representing binary data.
Here's an example using os.urandom
In [1]: random_bytes = os.urandom(4)In [2]: random_bytes
Out[2]: '\xfd\xa9\xbe\x87'In [3]: random_bytes = os.urandom(4)In [4]: random_bytes
Out[4]: '\r\x9eq\xce'
In the first example of random_bytes
, after each \x there seem to be values in hexadecimal form: fd a9 be 87.
In the second example, however, I don't understand why '\r\x9eq\xce'
is displayed.
Why does Python show me these random bytes in this particular representation? How should I interpret '\r\x9eq\xce'
?