Site icon i2tutorials

Python Convert bytes to String

Python Convert bytes to String

This article will guide you on how to convert bytes to string

 

Example 1:

 

s = b'abc'
print(type(s))

# bytes to string using decode()
s = b.decode()
print('After decoding to string =', s)
print(type(s))

 

Output:

 

 

Example 2:

 

You can also decode in the below manner.

 

b'xyz'.decode()

 

Output:

 

 

Exit mobile version