No. The idea is explicitly dismissed in the PEP:

For the same reason that we don't support bytes.format(), you may not combine 'f' with 'b' string literals. The primary problem is that an object's __format__() method may return Unicode data that is not compatible with a bytes string.

Binary f-strings would first require a solution for bytes.format(). This idea has been proposed in the past, most recently in PEP 461. The discussions of such a feature usually suggest either

  • adding a method such as __bformat__() so an object can control how it is converted to bytes, or

  • having bytes.format() not be as general purpose or extensible as str.format().

Both of these remain as options in the future, if such functionality is desired.

Answer from jwodder on Stack Overflow
🌐
Python
peps.python.org › pep-0498
PEP 498 – Literal String Interpolation | peps.python.org
In addition, raw f-strings may be combined with triple-quoted strings. For the same reason that we don’t support bytes.format(), you may not combine 'f' with 'b' string literals.
🌐
Medium
medium.com › @suryasekhar › string-prefixes-in-python-what-are-f-strings-and-r-strings-in-python-ca759810ebfa
String Prefixes in Python: What are f-strings and r-strings in Python | by Surya Sekhar Datta | Medium
September 15, 2024 - Discover how Python’s f-strings simplify string interpolation and how to use r-strings to handle raw text like file paths and regex.
🌐
Real Python
realpython.com › python-f-strings
Python's F-String for String Interpolation and Formatting – Real Python
November 30, 2024 - Python's f-strings provide a readable way to interpolate and format strings. They're readable, concise, and less prone to error than traditional string interpolation and formatting tools, such as the .format() method and the modulo operator (%). F-strings are also faster than those tools!
🌐
Finxter
blog.finxter.com › home › learn python blog › f-string python hex, oct, and bin: efficient number conversions
F-String Python Hex, Oct, and Bin: Efficient Number Conversions - Be on the Right Side of Change
March 27, 2023 - For converting strings to their hexadecimal, octal, and binary representations, you can use the following approach: import binascii text = "Hello, World!" # Convert the string to bytes text_bytes = text.encode('utf-8') # Use binascii to convert bytes to hex, oct, and bin hex_string = binascii.hexlify(text_bytes).decode('utf-8') oct_string = "".join([f"{char:o}" for char in text_bytes]) bin_string = "".join([f"{char:08b}" for char in text_bytes])
🌐
ReqBin
reqbin.com › code › python › trs5wpc0 › python-f-string-example
How to format string with f-string in Python?
July 27, 2023 - Click Execute to run Python F-String Example online and see the result. ... A Python string string is an array of 16-bit Unicode bytes (and 8-bit ANSI bytes for Python 2), where each string character is represented by one byte.
Find elsewhere
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.4 documentation
To read a file’s contents, call f.read(size), which reads some quantity of data and returns it as a string (in text mode) or bytes object (in binary mode). size is an optional numeric argument.
🌐
Python
peps.python.org › pep-0461
PEP 461 – Adding % formatting to bytes and bytearray | peps.python.org
%c will insert a single byte, either from an int in range(256), or from a bytes argument of length 1, not from a str. ... input type is something else? use its __bytes__ method [5] ; if there isn’t one, raise a TypeError · In particular, %b will not accept numbers nor str. str is rejected as the string to bytes conversion requires an encoding, and we are refusing to guess; numbers are rejected because:
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.4 documentation
>>> encoded_str_to_bytes = 'Python'.encode() >>> type(encoded_str_to_bytes) <class 'bytes'> >>> encoded_str_to_bytes b'Python' Changed in version 3.1: Added support for keyword arguments. Changed in version 3.9: The value of the errors argument is now checked in Python Development Mode and in debug mode. ... Return True if the string ends with the specified suffix, otherwise return False.
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
Before Python 3.6 we had to use the format() method. F-string allows you to format selected parts of a string.
🌐
Cito
cito.github.io › blog › f-strings
The new f-strings in Python 3.6 | Seasoned & Agile
December 24, 2016 - First, they are called f-strings ... get an f-string, similar to how you create a raw string by prefixing it with “r”, or you can use the prefixes “b” and “u” to designate byte strings and unicode strings. Note that the “u” prefix was only necessary in Python 2 (“Legacy ...
🌐
Medium
medium.com › @byte-pages › pythons-magical-f-strings-a-detailed-guide-4eb0e3c475b4
Python’s Magical F-Strings — A Detailed Guide✨ | Medium
May 19, 2024 - Ready to unravel the mysteries of otherworldly formats? F-strings are your key to unlocking them. Imprint your expressions with format codes like #x to unveil the hexadecimal secrets or #04x for a byte-sized revelation.
🌐
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 - What is a raw(r) string or format(f) string and when I should use them? What are the differences between Numpy/Pandas string and primitive Python strings? To understand the differences between byte string and Unicode string, we first need to know what “Encoding” and “Decoding” are.
🌐
GeeksforGeeks
geeksforgeeks.org › formatted-string-literals-f-strings-python
f-strings in Python - GeeksforGeeks
June 19, 2024 - To create an f-string, prefix the string with the letter “ f ”. The string itself can be formatted in much the same way that you would with str.format(). F-strings provide a concise and convenient way to embed Python expressions inside string literals for formatting.
🌐
Built In
builtin.com › data-science › python-f-string
Guide to String Formatting in Python Using F-strings | Built In
They provide a better way to format strings and make debugging easier, too. ... Summary: Python f-strings, introduced in version 3.6, allow cleaner string formatting by embedding variables directly.
🌐
DataCamp
datacamp.com › tutorial › python-f-string
Python f-string: A Complete Guide | DataCamp
December 3, 2024 - F-strings are string literals prefixed with 'f' or 'F' that contain expressions inside curly braces {}. These expressions are evaluated at runtime and then formatted using the __format__ protocol. Unlike traditional string formatting methods, f-strings provide a more straightforward and readable way to embed Python expressions directly within string literals.
🌐
The Python Coding Stack
thepythoncodingstack.com › p › bytes-python-built-in-unicode-utf-8-encoding
`bytes`: The Lesser-Known Python Built-In Sequence • And Understanding UTF-8 Encoding
June 1, 2024 - All code blocks are available in text format at the end of this article • #1 · The bytes literal looks very similar to the string one. You add b in front of the quotes. You're familiar with adding f in front of single or double (or triple) ...