Python f-strings: Use of “=” (very cool!)

In Python f-strings, the equal sign (=) is used to print both the variable name and its value in a string. It is used to facilitate print-debugging by expanding to the text of the expression, an equal sign, then the representation of the evaluated expression. For example, if you have a variable named x with a value of 5, you can use an f-string like this: f'{x=}' which will expand to 'x=5'⁷.

Try it out here!

Source: Conversation with Bing, 3/30/2023

(1) python – What does = (equal) do in f-strings inside the expression …. Accessed 3/30/2023.

(2) Python f-String Tutorial – String Formatting in Python Explained with …. Accessed 3/30/2023.

(3) Python f-strings: Everything you need to know! • datagy. Accessed 3/30/2023.

(4) Python 3’s f-Strings: An Improved String Formatting Syntax (Guide). Accessed 3/30/2023.

(5) PEP 498 – Literal String Interpolation | Accessed 3/30/2023.

(6) Modulo String Formatting in Python – Real Python. Accessed 3/30/2023.

(7) f-strings in Python – GeeksforGeeks. Accessed 3/30/2023.

(8) What does ‘f’ mean before a string in Python? – Stack Overflow. Accessed 3/30/2023.

This post was inspired by this tweet:

One Reply to “Python f-strings: Use of “=” (very cool!)”