Convert bytes to string in Python
Python bytes objects expose decode(). For UTF-8 data:
data = bytes([72, 101, 108, 108, 111])
text = data.decode("utf-8")
print(text) # HelloFor hexadecimal input:
text = bytes.fromhex("48 65 6c 6c 6f").decode("utf-8")Bytes are not characters by themselves
A byte is an 8-bit numeric value. A character encoding maps sequences of bytes to text. That is why storage conversion such as bytes to GB is pure arithmetic, while bytes to string is decoding.