-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
gh-85583: Add overview of formatted string literals (f-strings) to str
#132689
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
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Ezio Melotti <[email protected]> Originally-authored-by: [email protected]
9641c06
to
8d4bf9c
Compare
str
str
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.
Also more links to other pages? e.g. lexical analysis
(Should the title not be "...to stdtypes
"?)
@skirpichev I'd like to merge this soon, I saw you requested a review. Do you have any comments? A |
|
||
.. versionadded:: 3.6 | ||
.. versionchanged:: 3.7 | ||
The :keyword:`await` and :keyword:`async for` can be used in expressions |
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.
The :keyword:`await` and :keyword:`async for` can be used in expressions | |
:keyword:`await` and :keyword:`async for` can be used in expressions |
Either remove it or make it longer, IMO shorter is better.
Many restrictions on expressions within f-strings have been removed. | ||
Notably, nested strings, comments, and backslashes are now permitted. | ||
|
||
An :dfn:`f-string` (formally a :dfn:`formatted string literal`) is |
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.
An :dfn:`f-string` (formally a :dfn:`formatted string literal`) is | |
An :dfn:`f-string` (:dfn:`formatted string literal`) is |
Is it more formal? f-string is pretty much an abbreviation.
>>> f'{{x}} is {x}' | ||
'{x} is 42' | ||
|
||
Functions can also be used, and :ref:`format specifier <formatstrings>`: |
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.
Functions can also be used, and :ref:`format specifier <formatstrings>`: | |
Functions can also be used, and :ref:`format specifiers <formatstrings>`: |
Grammar
While debugging it may be helpful to see both the expression and its value, | ||
using the equals sign (``=``) after the expression. |
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.
While debugging it may be helpful to see both the expression and its value, | |
using the equals sign (``=``) after the expression. | |
While debugging it may be helpful to see both the expression and its value | |
by using the equals sign (``=``) after the expression. |
using the equals sign (``=``) after the expression. | ||
This preserves spaces within the brackets, and can be used with a converter. | ||
By default, the debugging operator uses the :func:`repr` (``!r``) conversion. | ||
For example: |
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.
Do we really need the "For example:" every time? Looking at the file it has mixed usage.
Replaces #21552.
📚 Documentation preview 📚: https://cpython-previews--132689.org.readthedocs.build/en/132689/library/stdtypes.html#formatted-string-literals-f-strings