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!
Top answer 1 of 16
5878
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!
2 of 16
430
Decode the byte string and turn it in to a character (Unicode) string.
Python 3:
encoding = 'utf-8'
b'hello'.decode(encoding)
or
str(b'hello', encoding)
Python 2:
encoding = 'utf-8'
'hello'.decode(encoding)
or
unicode('hello', encoding)
Real Python
realpython.com โบ convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python โ Real Python
November 26, 2025 - In the example above, .decode() uses UTF-8 encoding automatically since no encoding was specified. 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 ...
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
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
How To Convert Bytes To A String - Different Methods Explained
This article confuses more than it explains, I don't consider it very helpful to someone trying to understand the distinction between a character string and a byte string. You may want to look elsewhere for a good explanation. More on reddit.com
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
Videos
12:15
Convert Bytes to String [Python] - YouTube
01:27
How to convert bytes to a string in Python - YouTube
02:29
Python Program #89 - Convert Bytes to a String in Python - YouTube
04:03
How to convert bytes into strings in Python - YouTube
01:04
How to Convert Bytes to String in Python 3: A Complete Guide - YouTube
python how to convert bytes to string
GeeksforGeeks
geeksforgeeks.org โบ python โบ how-to-convert-bytes-to-string-in-python
How to Convert Bytes to String in Python ? - GeeksforGeeks
The str() function of Python returns the string version of the object. ... Itโs a useful alternative, especially when you're not calling it on a byte object directly. The codecs module provides an alternative way to decode bytes, especially useful when dealing with different encodings.
Published ย July 23, 2025
Python documentation
docs.python.org โบ 3 โบ library โบ stdtypes.html
Built-in Types โ Python 3.14.5rc1 documentation
Otherwise, the bytes object underlying ... bytes.decode(). See Binary Sequence Types โ bytes, bytearray, memoryview and Buffer Protocol for information on buffer objects. Passing a bytes object to str() without the encoding or errors arguments falls under the first case of returning the informal string representation ...
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.
Reddit
reddit.com โบ r/python โบ how to convert bytes to string in python?
r/Python on Reddit: How to convert bytes to string in python?
February 8, 2016 -
i am stuck in python programming. i read a line from the serial port
line=ser.readline() print(line)
when the above code is executed i get like
b'-83,-156,-205\r\n'
but i want only values like a=-83,b=-156,c=-205. how to extract these values/ how to get these values?
Top answer 1 of 3
3
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.
2 of 3
2
On python 3: line = ser.readline().decode() Also you can specify the character encoding: line = ser.readline().decode("ascii") line = ser.readline().decode("utf-8")
DataCamp
datacamp.com โบ tutorial โบ bytes-to-string-python
How to Convert Bytes to String in Python | DataCamp
June 12, 2024 - To convert bytes to strings in Python, we can use the .decode() method, specifying the appropriate encoding.
Mimo
mimo.org โบ glossary โบ python โบ string-decode
Python string decode(): Syntax, Usage, and Examples
The decode() method in Python is used to convert byte data into a Unicode string. In Python 3, strings are Unicode by default, so decode() applies specifically to bytes objects.
DigitalOcean
digitalocean.com โบ community โบ tutorials โบ python-string-encode-decode
Python String Encode and Decode: Complete Guide | DigitalOcean
August 3, 2022 - Python string encode() function is used to encode the string using the provided encoding. This function returns the bytes object. If we donโt provide encoding, โutf-8โ encoding is used as default. Python bytes decode() function is used to convert bytes to string object.
Facebook
facebook.com โบ groups โบ pythonneres โบ posts โบ 26207805565490392
Learn today: Converting Bytes to String in Python.
We cannot provide a description for this page right now
Scaler
scaler.com โบ home โบ topics โบ byte to string python
Byte to String Python - Scaler Topics
January 16, 2024 - We'll examine an illustration of how to decode a given byte stream using the codecs.decode() function. ... The map() method in python accepts a function and a Python iterable object (list, tuple, string, etc.) as inputs and returns a map object.
WsCube Tech
wscubetech.com โบ resources โบ python โบ programs โบ bytes-to-string
Convert Bytes to a String in Python (5 Programs)
October 29, 2025 - Learn to convert bytes to a string in Python with 5 simple programs. Clear examples and outputs make it easy to understand.