How to Convert Bytes to String in Python?
To convert bytes to string in Python, you can use the decode() method.
Example:
# bytes variable
b = b'Hello, World!'
# convert bytes to string
s = b.decode()
# print string
print(s) # output: Hello, World!
In the above example, the bytes variable b
is converted to a string using the decode() method. The resulting string is stored in a new variable named s
, which is then printed to the console.