3 Ways to convert bytes to String in Python

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")


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")


Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap