Sometimes, we want to convert bytes to a string with Python.
In this article, we’ll look at how to convert bytes to a string with Python.
How to convert bytes to a string with Python?
To convert bytes to a string with Python, we can use the decode
method.
For instance, we write:
decoded = b"abcde".decode("utf-8")
print(decoded)
We call decode
on a binary string with 'utf-8'
to decode it into a regular UTF-8 string.
Therefore, decoded
is 'abcde'
.
Conclusion
To convert bytes to a string with Python, we can use the decode
method.