Decode the bytes object to produce a string:

>>> b"abcde".decode("utf-8")
'abcde'

The above example assumes that the bytes object is in UTF-8, because it is a common encoding. However, you should use the encoding your data is actually in!

Answer from Aaron Maenpaa on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-bytes-to-string-in-python
How to Convert Bytes to String in Python ? - GeeksforGeeks
This method is used to convert from one encoding scheme, in which the argument string is encoded to the desired encoding scheme. This works opposite to the encode. ... It assumes the byte object is UTF-8 encoded unless specified otherwise. The str() function of Python returns the string version of the object.
Published   July 23, 2025
Discussions

python - How to convert a byte array to string? - Stack Overflow
I just finished creating a huffman compression algorithm . I converted my compressed text from a string to a byte array with bytearray(). Im attempting to decompress my huffman algorithm. My only c... More on stackoverflow.com
🌐 stackoverflow.com
How to convert a bytes array literally to string instead of converting to string?
Literally converting to string: repr(b)[2:-1] More on reddit.com
🌐 r/learnpython
8
0
May 11, 2022
How do I convert a string to bytes?
Or use the bytes() builtin function . An example: x = "abc☺xyz" print(x) y = bytes(x, encoding="utf-8") print(y) More on reddit.com
🌐 r/learnpython
15
6
August 8, 2023
How do i make a bytes object convert to a formatted string.
That's its representation. Print the string to see it formatted: >>> b = b"\tHello\nWorld" >>> s = b.decode() >>> s '\tHello\nWorld' >>> print(s) Hello World More on reddit.com
🌐 r/learnpython
5
1
February 14, 2025
🌐
freeCodeCamp
freecodecamp.org › news › python-bytes-to-string-how-to-convert-a-bytestring
Python Bytes to String – How to Convert a Bytestring
April 10, 2023 - Note that the decode() method can ... the decoder should expect more input. You can use the str() constructor in Python to convert a byte string (bytes object) to a string object....
🌐
Real Python
realpython.com › convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python – Real Python
November 26, 2025 - When the code runs, it converts the raw bytes fetched from the website into a readable HTML string, which can then be displayed or parsed further. The b prefix seen in the earlier byte representation disappears, and the result becomes a standard string: ... $ python decode_bytes.py Bytes: b'<!doctype html><html lang="en"><head><title>Example Domain</title>… String: <!doctype html><html lang="en"><head><title>Example Domain</title>…
🌐
DataCamp
datacamp.com › tutorial › bytes-to-string-python
How to Convert Bytes to String in Python | DataCamp
June 12, 2024 - A bytes object is an immutable sequence of bytes that can be converted to a string using one of several character encodings. The main route to convert Python bytes to a string is the .decode() method, which allows users to choose an encoding and an error-handling strategy.
🌐
Delft Stack
delftstack.com › home › howto › python › python convert bytearray to string
How to Convert Bytearray to String in Python | Delft Stack
February 2, 2024 - If we have a bytearray containing string characters with the utf-8 encoding and want to convert that array into a string variable, we can use the built-in bytes() function in Python.
🌐
FavTutor
favtutor.com › blogs › bytes-to-string-python
4 Methods to Convert Bytes to String in Python (with code)
February 8, 2023 - Then we use the decode() function to decode x and now when we print x, we get “Example”, a string and when we check the type using the type() function, we can see that the type is now in string. Similarly, we can decode byte arrays with the same function and convert them into strings.
Find elsewhere
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python convert bytes to string
Python Convert Bytes to String - Spark By {Examples}
May 31, 2024 - You can convert bytes to strings very easily in Python by using the decode() or str() function. Bytes and strings are two data types and they play a
🌐
Analytics Vidhya
analyticsvidhya.com › home › 3 ways to convert bytes to string in python
3 Ways to Convert Bytes to String in Python
March 26, 2025 - A. You can convert bytes to a string using .decode('utf-8') in Python, which decodes the byte object into a human-readable string using UTF-8 encoding. Q2. How many bytes is a string?
🌐
GeeksforGeeks
geeksforgeeks.org › python-convert-string-to-bytes
Convert String to bytes-Python - GeeksforGeeks
2 min read Convert Bytearray to Hexadecimal String - Python · We are given a byte array a=bytearray([15, 255, 100, 56]) we need to convert it into a hexadecimal string that looks like: 0fff6438.
Published   April 27, 2025
🌐
Reddit
reddit.com › r/learnpython › how to convert a bytes array literally to string instead of converting to string?
r/learnpython on Reddit: How to convert a bytes array literally to string instead of converting to string?
May 11, 2022 -

I want to convert an encrypted byte array into literal string for example:

Consider the below text as my bytes array:

b'x\xaa\xfc""|\xe2\xf7\xd1\xdaH\xf0\x8e\xa9>j>\x08\xd3\xad\xe2\xa3W\xdb\x1b\xd5\xa1\xb2q\x89V\xf0Zg\xd6a\x02\x12'

I want to convert it into:

'x\xaa\xfc""|\xe2\xf7\xd1\xdaH\xf0\x8e\xa9>j>\x08\xd3\xad\xe2\xa3W\xdb\x1b\xd5\xa1\xb2q\x89V\xf0Zg\xd6a\x02\x12'

The same bytes array into string format.

I am unable to phrase this question properly to search in google, thought I can get help to either solve this issue or to understand how to phrase this issue.

P.S: First post in this sub, If I made any mistakes please do point it out.

Edit: If anyone wants to know why I need it, just consider that the function I am using only takes string as input and to convert that function such that it will use the encrypted byte array as input is a big hassle and I want the encrypted byte array to stay as in encrypted format instead of decoding it.

🌐
Stack Abuse
stackabuse.com › convert-bytes-to-string-in-python
Convert Bytes to String in Python
November 27, 2020 - In this tutorial, we'll go over examples of how to convert bytes to a string in Python 2 and 3. We'll use the decode() function, str() function as well as the codecs module.
🌐
Javatpoint
javatpoint.com › how-to-convert-bytes-to-string-in-python
How to convert Bytes to string in Python - Javatpoint
How to convert Bytes to string in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
🌐
KDnuggets
kdnuggets.com › convert-bytes-to-string-in-python-a-tutorial-for-beginners
Convert Bytes to String in Python: A Tutorial for Beginners - KDnuggets
July 15, 2024 - Use the str() constructor to convert a valid bytes object to a string. Use the decode() function from the codecs module that is built into the Python standard library to convert a valid bytes object to a string.
🌐
Flexiple
flexiple.com › python › bytes-to-string
Python Bytes to String – How to Convert a Bytestring - Flexiple
February 23, 2024 - To convert bytes to a string, Python uses the decode method. This method applies a specific encoding to transform bytes into a string.
🌐
Reddit
reddit.com › r/learnpython › how do i convert a string to bytes?
r/learnpython on Reddit: How do I convert a string to bytes?
August 8, 2023 -

Suppose I something like

s = "GW\x25\001"

How do I convert that string to bytes, interpreting the backslashes as escapes? In other words, the resulting byte array should be of length 4.

UPDATE: Hmmm, I was taking the string from sys.argv[1], which seems to complicate things and not make it turn out as expected. So I'm still not sure what the answer is.

🌐
Programiz
programiz.com › python-programming › examples › bytes-to-string
Python Program to Convert Bytes to a String
To understand this example, you should have the knowledge of the following Python programming topics: ... Using decode(), you can convert bytes into string. Here, we have used utf-8 for decoding.
🌐
Vultr
docs.vultr.com › python › examples › convert-bytes-to-a-string
Python Program to Convert Bytes to a String | Vultr Docs
November 27, 2024 - Converting bytes to a string in Python is straightforward with the decode() method, which handles various encodings and provides robust solutions for error management. Whether dealing with simple data or complex byte sequences, Python's ...
🌐
Net Informations
net-informations.com › python › iq › byte.htm
How to convert bytes to string in Python?
In the above example, first defined ... string is assigned to the variable 'myS'. Another way to convert bytes to a string in Python is to use the str() function....