How to Convert Bytearray to String in Python


If you need to convert a Bytearray to a String in Python, then you can do the following:

Option 1 – Using bytes()

b = bytearray("test", encoding="utf-8")
str1 = bytes(b)
print(str1)

Option 2 – Using bytearray.decode()

b = bytearray("test", encoding="utf-8")
str1 = b.decode()
print(str1)