Convert bytes to a string

Explanation

To convert bytes to a string first learn what is string. So String is a collection of objects. So an object in a string can be of different types. It can be int, float, string, etc. And if you want to convert a byte to a string you have to follow the below steps: 

You need to decode the bytes object to produce a string:

>>> b"abcde"
b'abcde'

# utf-8 is used here because it is a very common encoding, but you
# need to use the encoding your data is actually in.
>>> b"abcde".decode("utf-8") 
'abcde'

 

Also read, How to remove local files from the current Git working tree

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *