I need to convert the next bytearray to string:
Num = bytearray()
I have tried
Num = bytearray(str)
but that's not the solution
To convert a list to a string, use Python List Comprehension and the join() function. The list comprehension will traverse the elements one by one, and the join() method will concatenate the list's elements into a new string and return it as output.
Similarly, Decoding is process to convert a Byte object to String. It is implemented using decode() . A byte string can be decoded back into a character string, if you know which encoding was used to encode it.
As t.m.adam said in the comments, use bytearray.decode
b = bytearray("test", encoding="utf-8")
b.decode()
#> 'test'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With