There are many ways in which we can convert bytes to String in Python, let's take a look at three such examples.
Example 1: Using decode() method
bytes_data = b"This is data in bytes"
string_data = bytes_data.decode("utf-8")
print(string_data)
Example 2: Using str() method
string_data = str(bytes_data, "utf-8")
Example 3: Using bytes.decode() method
string_data = bytes_data.decode("utf-8")
Documentation: 1. bytes.decode()
https://docs.python.org/3/library/stdtypes.html#bytes.decode
2. str(): https://docs.python.org/3/library/stdtypes.html#str
3. str.decode(): https://docs.python.org/2/library/stdtypes.html#str.decode
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!