As of Python 3.5, % formatting will work for bytes, too!

This was part of PEP 461, authored by Ethan Furman:

PEP: 461
Title: Adding % formatting to bytes and bytearray
Version: $Revision$
Last-Modified: $Date$
Author: Ethan Furman <ethan at stoneleaf.us>
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 2014-01-13
Python-Version: 3.5
Post-History: 2014-01-14, 2014-01-15, 2014-01-17, 2014-02-22, 2014-03-25,
               2014-03-27
Resolution:


Abstract
========

This PEP proposes adding % formatting operations similar to Python 2's ``str``
type to ``bytes`` and ``bytearray`` [1]_ [2]_.


Rationale
=========

While interpolation is usually thought of as a string operation, there are
cases where interpolation on ``bytes`` or ``bytearrays`` make sense, and the
work needed to make up for this missing functionality detracts from the overall
readability of the code.


Motivation
==========

With Python 3 and the split between ``str`` and ``bytes``, one small but
important area of programming became slightly more difficult, and much more
painful -- wire format protocols [3]_.

This area of programming is characterized by a mixture of binary data and
ASCII compatible segments of text (aka ASCII-encoded text).  Bringing back a
restricted %-interpolation for ``bytes`` and ``bytearray`` will aid both in
writing new wire format code, and in porting Python 2 wire format code.

Common use-cases include ``dbf`` and ``pdf`` file formats, ``email``
formats, and ``FTP`` and ``HTTP`` communications, among many others.

PEP 461 was accepted by Guido van Rossum on March 27, 2014:

Accepted. Congrats with marshalling yet another quite contentious discussion, and putting up with my last-minute block-headedness!

From this, we can obviously conclude that % is no longer scheduled for deprecation (as was announced with Python 3.1).

Answer from Ecir Hana on Stack Overflow
Top answer
1 of 6
60

As of Python 3.5, % formatting will work for bytes, too!

This was part of PEP 461, authored by Ethan Furman:

PEP: 461
Title: Adding % formatting to bytes and bytearray
Version: $Revision$
Last-Modified: $Date$
Author: Ethan Furman <ethan at stoneleaf.us>
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 2014-01-13
Python-Version: 3.5
Post-History: 2014-01-14, 2014-01-15, 2014-01-17, 2014-02-22, 2014-03-25,
               2014-03-27
Resolution:


Abstract
========

This PEP proposes adding % formatting operations similar to Python 2's ``str``
type to ``bytes`` and ``bytearray`` [1]_ [2]_.


Rationale
=========

While interpolation is usually thought of as a string operation, there are
cases where interpolation on ``bytes`` or ``bytearrays`` make sense, and the
work needed to make up for this missing functionality detracts from the overall
readability of the code.


Motivation
==========

With Python 3 and the split between ``str`` and ``bytes``, one small but
important area of programming became slightly more difficult, and much more
painful -- wire format protocols [3]_.

This area of programming is characterized by a mixture of binary data and
ASCII compatible segments of text (aka ASCII-encoded text).  Bringing back a
restricted %-interpolation for ``bytes`` and ``bytearray`` will aid both in
writing new wire format code, and in porting Python 2 wire format code.

Common use-cases include ``dbf`` and ``pdf`` file formats, ``email``
formats, and ``FTP`` and ``HTTP`` communications, among many others.

PEP 461 was accepted by Guido van Rossum on March 27, 2014:

Accepted. Congrats with marshalling yet another quite contentious discussion, and putting up with my last-minute block-headedness!

From this, we can obviously conclude that % is no longer scheduled for deprecation (as was announced with Python 3.1).

2 of 6
32

Another way would be:

"{0}, {1}, {2}".format(1, 2, 3).encode()

Tested on IPython 1.1.0 & Python 3.2.3

๐ŸŒ
Python
peps.python.org โ€บ pep-0461
PEP 461 โ€“ Adding % formatting to bytes and bytearray | peps.python.org
This PEP proposes adding % formatting operations similar to Python 2โ€™s str type to bytes and bytearray 1 2.
๐ŸŒ
Real Python
realpython.com โ€บ convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python โ€“ Real Python
November 26, 2025 - Here, https://example.com/ can be replaced with the site that youโ€™ve chosen. When you use the urlopen() function, Python automatically returns the data as bytes, since data is transmitted in that raw format. The strings you see are simply a human-readable representation of these bytes.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ struct.html
struct โ€” Interpret bytes as packed binary data
February 23, 2026 - Unpack from the buffer buffer (presumably packed by pack(format, ...)) according to the format string format. The result is a tuple even if it contains exactly one item. The bufferโ€™s size in bytes must match the size required by the format, as reflected by calcsize().
๐ŸŒ
Python
bugs.python.org โ€บ issue3982
Issue 3982: support .format for bytes - Python tracker
September 27, 2008 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide ยท This issue has been migrated to GitHub: https://github.com/python/cpython/issues/48232
๐ŸŒ
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.
๐ŸŒ
Vultr
docs.vultr.com โ€บ python โ€บ examples โ€บ convert-bytes-to-a-string
Python Program to Convert Bytes to a String | Vultr Docs
November 27, 2024 - byte_data = b'\xc2\xa9 2021 Python' string_data = byte_data.decode('utf-8') print(string_data) Explain Code
Find elsewhere
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ python string to bytes, bytes to string
Python String to bytes, bytes to String - AskPython
February 16, 2023 - Pythonโ€™s CPython library provides us with bytes() function to convert String to bytes. ... Note: The UTF-8 format is used for the purpose of encoding.
๐ŸŒ
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 - In this example, we define a byte string b"Hello, world!" and use the str() constructor to convert it to a string object. We specify the encoding format as utf-8 using the encoding parameter. Finally, we print the resulting string to the console. We can also use the bytes() constructor, a built-in Python function used to create a new bytes object.
๐ŸŒ
Real Python
realpython.com โ€บ python-bytes
Bytes Objects: Handling Binary Data in Python โ€“ Real Python
January 20, 2025 - The format specifier ("08b") ensures appropriate padding to maintain a consistent length for each byte. Lastly, you combine the resulting bit patterns into a single string with spaces separating them.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-string-to-bytes
Convert String to bytes-Python - GeeksforGeeks
Explanation: bytes() constructor converts a string to bytes using the specified encoding, here "utf-8", allowing the string to be processed as binary data. bytearray() constructor works just like bytes(), but it creates a mutable sequence of bytes.
Published ย  July 11, 2025
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ bytes
Python bytes()
Become a certified Python programmer. Try Programiz PRO! ... The bytes() method returns an immutable bytes object initialized with the given size and data. ... # convert string to bytes byte_message = bytes(message, 'utf-8') print(byte_message) # Output: b'Python is fun'
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ bytes
Python Bytes: Syntax, Usage, and Examples
You use them when dealing with ... 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....
๐ŸŒ
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 - As explained above, you can encode them to the byte string (b string), and the byte string can be decoded back to the Unicode string. u'Hi'.encode('ASCII') > b'Hi'b'\x48\x69'.decode('ASCII') > 'Hi' In Python IDE, usually, the byte string will be automatically decoded using โ€œASCIIโ€ when printed out, so thatโ€™s why the first result is human-readable (bโ€™Hi').
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ stdtypes.html
Built-in Types โ€” Python 3.14.4 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). For example: ... For more information on the str class and its methods, see Text Sequence Type โ€” str and the String Methods section below. To output formatted strings, see the f-strings and Format string syntax sections.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ 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 ย  April 14, 2025
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ bytes-to-string
Python Bytes to String โ€“ How to Convert a Bytestring - Flexiple
February 23, 2024 - Converting a bytestring to a string ... files, or when interacting with web data. Python provides straightforward methods to accomplish this conversion, ensuring that bytes are accurately translated into a readable string format....