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
base: main
Are you sure you want to change the base?
Conversation
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.
| @@ -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: | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')?
Maybe something like And this tutorial section could possibly also use an example for printing the curly brackets too
|
#81039
https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals
https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging