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
🌐
Medium
medium.com › data-science › byte-string-unicode-string-raw-string-a-guide-to-all-strings-in-python-684c4c4960ba
Byte string, Unicode string, Raw string — A Guide to all strings in Python | by Guangyuan(Frank) Li | TDS Archive | Medium
November 23, 2022 - In summary, we talked about the different representations of “string” in Python. Starting with the default Unicode string (u string), we touched on how it relates to Byte string (b string). Understanding the conversion is very important because sometimes the standard output from other programs will be in the format of bytes, and we need to first decode them to Unicode string for further Streaming operation.
Discussions

[Python 3] Understanding the difference between byte string and strings.
The bytes that python is using under the covers aren't necessarily the bytes that you want. If I want to put the word café on my website then I probably need the bytes 0x63 0x61 0x66 0xc3 0xa9. But the bytes that python currently uses to represent the string 'café' under the covers is actually 0x63 0x61 0x66 0xe9. I can't use the same bytes that python uses because python doesn't use the bytes I need. Python chooses to represent things using a certain pattern of bytes for it's own reasons, but there are many different ways to express the same thing using bytes. You may wish to (or be forced to) use a different one than what python picks. bytes objects allow you to do that. By not having your code rely on the way that python represents things in bytes, it makes it possible for python to change the representation if it finds a better way. Dictionaries were recently updated to make them significantly smaller, but in order to do this python had to change the byte representation of dictionaries. They would have broken other code that relied on that representation. More on reddit.com
🌐 r/learnpython
8
7
October 20, 2018
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 to convert bytes to string in python?
Try this: line = ser.readline().strip() values = line.decode('ascii').split(',') a, b, c = [int(s) for s in values] The call to .strip() removes the trailing newline. The call .decode('ascii') converts the raw bytes to a string. .split(',') splits the string on commas. Finally the call [int(s) for s in value] is called a list comprehension, and produces a list of integers. More on reddit.com
🌐 r/Python
3
1
February 8, 2016
Converting bytes to string to bytes
How can I convert bytes to string to bytes back? Here’s what I’m trying: from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding message = b"A message I want to sign" signature = private_key.sign( message, padding.PSS( mgf=padding... More on discuss.python.org
🌐 discuss.python.org
8
0
October 28, 2021
🌐
Real Python
realpython.com › convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python – Real Python
July 18, 2026 - What is the difference between bytes and str in Python?Show/Hide · bytes holds raw 8-bit values, while str holds Unicode text. Convert from bytes to text with .decode() and from text to bytes with .encode(). Take the Quiz: Test your knowledge with our interactive “How to Convert Bytes to Strings in Python” quiz.
🌐
Python
docs.python.org › 3 › builtins › stdtypes.html
Built-in Types — Python 3.14.7 documentation
Passing a bytes object to str() without the encoding or errors arguments falls under the first case of returning the informal string representation (see also the -b command-line option to Python).
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-bytes-to-string-in-python
How to Convert Bytes to String in Python ? - GeeksforGeeks
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
🌐
Mimo
mimo.org › glossary › python › bytes
Python Bytes: Syntax, Usage, and Examples
In Python 3, text is stored as str (Unicode) and binary data as bytes; this separation between data types helps prevent encoding bugs when mixing unicode and text encodings. ... A bytes object is defined by prefixing a string literal with a b. You can also use the bytes() constructor to create a bytes object from a string or an iterable of integers.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › [python 3] understanding the difference between byte string and strings.
r/learnpython on Reddit: [Python 3] Understanding the difference between byte string and strings.
October 20, 2018 -

I've been reading a bit about how python 3 strings are based around unicode and I ran into the the concept of a byte string.

Here's the definition of a byte string I've taken from stackoverflow:

A byte string is a sequence of bytes. It isn't human-readable. Under the hood, everything must be converted to a byte string before it can be stored in a computer.

What I don't understand is if the normal python string type is just a sequence of Unicode characters, which at the low level is stored as bytes, why does a byte string even need to exist? Since at the low level a normal python string is just storing the Unicode sequence as bytes anyways? How is a byte string not redundant?

Top answer
1 of 2
2
The bytes that python is using under the covers aren't necessarily the bytes that you want. If I want to put the word café on my website then I probably need the bytes 0x63 0x61 0x66 0xc3 0xa9. But the bytes that python currently uses to represent the string 'café' under the covers is actually 0x63 0x61 0x66 0xe9. I can't use the same bytes that python uses because python doesn't use the bytes I need. Python chooses to represent things using a certain pattern of bytes for it's own reasons, but there are many different ways to express the same thing using bytes. You may wish to (or be forced to) use a different one than what python picks. bytes objects allow you to do that. By not having your code rely on the way that python represents things in bytes, it makes it possible for python to change the representation if it finds a better way. Dictionaries were recently updated to make them significantly smaller, but in order to do this python had to change the byte representation of dictionaries. They would have broken other code that relied on that representation.
2 of 2
1
What a language does under the hood is one thing, and what it exposes to the user is another one. As a meta-joke: the code you write in, say, C, is compiled to bytes. All your functions, variables, loops, everything is converted into raw bytes. You can open up your binary in a hex editor and take a look at them. Makes zero sense, huh? Wait a minute, why have functions, variables, loops and stuff if you can just write raw bytes yourself? If you can literally write your program by punching in bytes? (This is 100% serious, actually). Aren’t all of the constructs mentioned above kinda... redundant, then? Think about it: programming languages provide abstractions so that you could express more sophisticated ideas more naturally. In Python you just write print(“stuff”) and may not even have a clue about how in the world this makes stuff appear in the console, while this may invoke tons of code under the hood. Python’s strings let you do operations on strings and not care how the data is being stored internally. You can, say, concatenate, split, convert to uppercase etc any Unicode string. You don’t have to deal with encoding, you don’t have to deal with endianness, nothing. You just do operations on human-readable strings. What if you want to work with raw bytes, though? What if, for example, you need to communicate with a C program, which doesn’t have a notion of “string”? (See? Plain C is not abstract enough) This is where you use bytes. You can encode your strings the way you want (the way your C code understands them, for example). What if you want to send stuff over the network? The latter doesn’t have a notion of “string” either. So you have to pack your data accordingly (that’s what the struct module does) and send these raw bytes. Also, a string can always be converted to raw bytes, but it doesn’t necessarily work the other way round. For example, you can’t have null-bytes in strings. But what if you need null-bytes? That’s where you use bytes or bytearray.
🌐
Theunterminatedstring
theunterminatedstring.com › python-bits-and-bytes
Python Bits and Bytes - The Unterminated String
May 19, 2018 - The str object has an encode() method to return the bytes representation of the 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.

🌐
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 - You can use the str() constructor in Python to convert a byte string (bytes object) to a string object. This is useful when we are working with data that has been encoded in a byte string format, such as when reading data from a file or receiving ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-convert-string-to-bytes
Convert String to bytes-Python - GeeksforGeeks
In this method, we manually convert each character in the string into its ASCII value using the ord() function, then combine them into a byte sequence. ... Explanation: List comprehension converts each character in "Hello" to its ASCII value ...
Published: July 11, 2025
🌐
DataCamp
datacamp.com › tutorial › bytes-to-string-python
How to Convert Bytes to String in Python | DataCamp
June 12, 2024 - The .decode() method returns a string representing the bytes object. In this example, UTF-8 decoding is used. UTF-8 is the default encoding, so it's not required in the example above, but we can also use other encodings. Python has a built-in bytes data structure, which is an immutable sequence of integers in the range 0 to 255.
🌐
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 - Handle potential decoding errors using the errors parameter with options like ignore or replace. Use the str() constructor to convert a valid bytes object to a string. Use the decode() function from the codecs ...
🌐
Python.org
discuss.python.org › python help
Converting bytes to string to bytes - Python Help - Discussions on Python.org
October 28, 2021 - How can I convert bytes to string to bytes back? Here’s what I’m trying: from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding message = b"A message I want to sign" signature = private_key.sign( message, padding.PSS( mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.MAX_LENGTH ), hashes.SHA256() ) converting the signature using base64 encode and decode methods to string.
🌐
Wyzant
wyzant.com › resources › ask an expert
Convert bytes to a string? | Wyzant Ask An Expert
April 3, 2019 - I mean, using the "batteries" instead of doing it manually. And I'd like it to be ok with Python 3. ... Use the built-in decode method for the bytes class. This will return a string object.
🌐
Python.org
discuss.python.org › python help
Converting integer to byte string problem in python 3 - Python Help - Discussions on Python.org
August 27, 2020 - I have a library function that is failing because I cannot seem to properly convert an integer to a proper byte string except by using a literal. Can someone explain why I get 3 different results from 3 different ways to convert an integer to a byte string? Using a literal, which is the only way the library call works produces this: >>> print(b'1') b'1' Using the builtin bytes function, which the library call rejects, is really strange: >>> i=1 >>> print(bytes(i)) b'\x00' Finally using the...
🌐
Real Python
realpython.com › python-bytes
Bytes Objects: Handling Binary Data in Python – Real Python
March 5, 2025 - By now, you’re familiar with creating bytes instances from scratch and from strings, as well as manipulating them. However, the default string representation of byte sequences in the REPL isn’t always the most readable. Next up, you’ll discover ways to customize the display of bytes, making them easier to understand. When your byte sequence contains only ASCII characters, its default representation in the Python REPL looks similar to that of a string:
🌐
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 - The decode() method is the most straightforward way to convert bytes to a string in Python. It takes an encoding parameter, which specifies the encoding to be used.
🌐
FavTutor
favtutor.com › blogs › bytes-to-string-python
4 Methods to Convert Bytes to String in Python (with code)
February 8, 2023 - Here, we accessed the column of bytes using dataframe indexing offered by Pandas and we used the .str.decode() function with a “utf-8” parameter to convert every value of the dataframe to a string. Encoding and decoding are essential knowledge one must possess to be a good python programmer because of how often encoding and decoding could be necessary. From Data Cleaning to Data Encryption to much simpler use cases, encoding and decoding are highly used in python.