close

How do I get rid of the b-prefix in a string in python?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I get rid of the b-prefix in a string in python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I get rid of the b-prefix in a string in python?

  1. How do I get rid of the b-prefix in a string in python?

    You need to decode it to convert it to a string. Check the answer here about bytes literal in python3.

  2. get rid of the b-prefix in a string in python

    You need to decode it to convert it to a string. Check the answer here about bytes literal in python3.

Method 1

you need to decode the bytes of you want a string:

b = b'1234'
print(b.decode('utf-8'))  # '1234'

Method 2

You need to decode it to convert it to a string. Check the answer here about bytes literal in python3.

In [1]: b'I posted a new photo to Facebook'.decode('utf-8')
Out[1]: 'I posted a new photo to Facebook'

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read