I have some bytes.
bytes
b'x01x02x03'
And an int in range 0..255.
int
5
Now I want to append the int to the bytes like this:
b'x01x02x03x05'
How to do it? There is no append method in bytes. I don't even know how to make the integer become a single byte.
append
>>> bytes(5) b'x00x00x00x00x00'
bytes is immutable. Use bytearray.
bytearray
xs = bytearray(b'x01x02x03') xs.append(5)
1.4m articles
1.4m replys
5 comments
56.9k users