Use decode:
>>> print(b'hello'.decode())
hello
Answer from sdaau on Stack OverflowGeeksforGeeks
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.
Published July 23, 2025
Alliow `bytes(mystring)` without specifying the encoding - Ideas - Discussions on Python.org
", line 1, in "hello".encode() b'hello' For consistency, I would suggest that calling bytes on a str object without an encoding also assumes UTF-8 by default, as ... More on discuss.python.org
How do I get rid of the 'b'
print(a.decode('utf-8')) More on reddit.com
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
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
Videos
08:35
str vs bytes in Python - YouTube
02:33
Best way to convert string to bytes in Python 3? - YouTube
04:11
How To Encode String To Bytes In Python - YouTube
04:03
How to convert bytes into strings in Python - YouTube
02:29
Python Program #89 - Convert Bytes to a String in Python - YouTube
01:27
How to convert bytes to a string in Python - YouTube
Java2Blog
java2blog.com › home › python › print bytes without b in python
Print Bytes without b in Python - Java2Blog
September 21, 2022 - The repr() function is similar to the str() constructor in Python. We can use it to get a string representation of different objects. For a byte object, the repr() function invokes the internal bytes.__repr__ magic method. It returns the bytes object as a string and we can manually slice off ...
Real Python
realpython.com › convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python – Real Python
October 5, 2025 - How do you convert bytes to a string in Python?Show/Hide · Call .decode() on the bytes object. It returns a str, using UTF-8 by default unless you pass a different character encoding. Which encoding should you use with .decode()?Show/Hide · Use UTF-8 for most modern text because it is the standard on the web and across platforms. If the data source declares a specific character set, pass that name to .decode(). How can you handle decoding errors without ...
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. ... Get your team access to the full DataCamp for business platform.
Reddit
reddit.com › r/learnpython › how do i get rid of the 'b'
r/learnpython on Reddit: How do I get rid of the 'b'
January 21, 2024 -
input:
s = 'ਅ'
a = s.encode('ascii', 'backslashreplace')
print(a)
output:
b'\\u0a05'
how do I get rid of the b'\ ? i just want it to say \u0a05
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")
Python.org
discuss.python.org › python help
Converting bytes to string to bytes - Python Help - Discussions on Python.org
October 27, 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.
Net Informations
net-informations.com › python › iq › byte.htm
How to convert bytes to string in Python?
Then decoded the bytearray object ... byte values and you want to convert them to a string without using the b prefix, you can use the map() function along with the chr() function....
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to convert python bytes to string without the ‘b’
5 Best Ways to Convert Python Bytes to String Without the 'b' - Be on the Right Side of Change
February 23, 2024 - import codecs bytes_data = b'Encoding with codecs' str_data = codecs.decode(bytes_data, 'utf-8') print(str_data) ... This code utilizes the codecs module to decode a bytes object into a string. The example specifies UTF-8 as the encoding scheme, which is commonly used. A bytearray is a mutable sequence of bytes in Python.
Scaler
scaler.com › home › topics › byte to string python
Byte to String Python - Scaler Topics
January 16, 2024 - We may use the built-in chr() method to do this. We'll use the map function in this example to convert a byte to a string without requiring the prefix b. Let us look at an example to comprehend the concept better.
Readthedocs
portingguide.readthedocs.io › en › latest › strings.html
Strings — Conservative Python 3 Porting Guide 1.0 documentation
Quoted string literals can be prefixed with b or u to get bytes or text, respectively. These prefixes work both in Python 2 (2.6+) and 3 (3.3+). Literals without these prefixes result in native strings.