Considering that the bytes
type is not necessarily a string, how can one see the actual bytes (ones and zeros, or octal/hexadecimal representation of such) of a bytes
object? Trying to print()
or pprint()
such an object results in printing the string representation of the object (assuming some encoding, probably ASCII or UTF-8) preceded by the b
character to indicate that the datatype is in fact bytes:
$ python3
Python 3.2.3 (default, Oct 19 2012, 19:53:16)
>>> from pprint import pprint
>>> s = 'hi'
>>> print(str(type(s)))
<class 'str'>
>>> se = s.encode('utf-8')
>>> print(str(type(se)))
<class 'bytes'>
>>> print(se)
b'hi'
>>> pprint(se)
b'hi'
>>>
Note that I am specifically referring to Python 3. Thanks!