Skip to content

Commit a592f84

Browse files
miss-islingtonslateny
authored andcommitted
gh-81039: Add small example of f-string's "=}" to tutorial (gh-92291) (gh-96989)
(cherry picked from commit 4b81139) Co-authored-by: Stanley <[email protected]> Co-authored-by: Stanley <[email protected]>
1 parent 50c0a22 commit a592f84

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Doc/tutorial/inputoutput.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,17 @@ applies :func:`repr`::
133133
>>> print(f'My hovercraft is full of {animals!r}.')
134134
My hovercraft is full of 'eels'.
135135

136-
For a reference on these format specifications, see
136+
The ``=`` specifier can be used to expand an expression to the text of the
137+
expression, an equal sign, then the representation of the evaluated expression:
138+
139+
>>> bugs = 'roaches'
140+
>>> count = 13
141+
>>> area = 'living room'
142+
>>> print(f'Debugging {bugs=} {count=} {area=}')
143+
Debugging bugs='roaches' count=13 area='living room'
144+
145+
See :ref:`self-documenting expressions <bpo-36817-whatsnew>` for more information
146+
on the ``=`` specifier. For a reference on these format specifications, see
137147
the reference guide for the :ref:`formatspec`.
138148

139149
.. _tut-string-format:

Doc/whatsnew/3.8.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ Android and Cygwin, whose cases are handled by the script);
250250
this change is backward incompatible on purpose.
251251
(Contributed by Victor Stinner in :issue:`36721`.)
252252

253+
.. _bpo-36817-whatsnew:
253254

254255
f-strings support ``=`` for self-documenting expressions and debugging
255256
----------------------------------------------------------------------

0 commit comments

Comments
 (0)