The answers to this question make it seem like there are two ways to convert an integer to a bytes
object in Python 3. They show
s = str(n).encode()
and
n = 5
bytes( [n] )
Being the same. However, testing that shows the values returned are different:
print(str(8).encode())
#Prints b'8'
but
print(bytes([8])) #prints b'\x08'
I know that the first method changes the int 8
into a string (utf-8
I believe) which has the hex value of 56, but what does the second one print? Is that just the hex value of 8? (a utf-8
value of backspace?)
Similarly, are both of these one byte in size? It seems like the second one has two characters == two bytes but I could be wrong there...