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

print(string_data)

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


Documentation:
-

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


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap