Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-81039: Add small description of f-string's "=}" to tutorial #92291

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Hmm, is this the best example? The main use case for this feature is for debugging, and there doesn't really seem to be any debugging going on in this example.

@AlexWaygood AlexWaygood requested a review from ericvsmith May 4, 2022
@@ -133,7 +133,14 @@ applies :func:`repr`::
>>> print(f'My hovercraft is full of {animals!r}.')
My hovercraft is full of 'eels'.

For a reference on these format specifications, see
The ``=`` specifier can be used to expand an expression and its evaluation:
Copy link
Member

@ericvsmith ericvsmith May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it say something about the text of the expression? "Expand an expression" doesn't sound like that, to me.

This should also mention that it's the repr that's printed.

Copy link
Contributor Author

@slateny slateny May 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try to condense the wording a bit for the tutorial and just rely more on the example, but on a second read through you're definitely right that it sounds off. If borrowing the wording from the what's new,

The = specifier can be used to expand an expression to the text of the expression, an equal sign, then the representation of the evaluated expression.

leaving out some information gives,

The = specifier can be used to expand an expression to itself and the representation of its evaluation.

Would that work, or would you prefer the original wording? I'm also not too sure what the difference is between the 'representation of an evaluation' vs just 'evaluation'. Say for i=1, would the representation be i.__repr__() and the evaluation eval('i')?

@slateny
Copy link
Author

@slateny slateny commented May 5, 2022

Hmm, is this the best example? The main use case for this feature is for debugging, and there doesn't really seem to be any debugging going on in this example.

Maybe something like

bugs = 'roaches'
count = '13'
area = 'living room'
print(f'Debugging: {bugs=} {count=} {area=}')
...

And this tutorial section could possibly also use an example for printing the curly brackets too

... And you can escape curly brackets in f-strings by using two:

...
print(f'Debugging: {{{bugs=} {count=} {area=}}}')
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants