summaryrefslogtreecommitdiff
path: root/Doc/library/string.rst
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-02-13 00:41:37 +0000
committerMartin Panter <vadmium+py@gmail.com>2016-02-13 00:41:37 +0000
commitbc1ee460dcbe5811ebb10a6cacd8d3670846f039 (patch)
tree1ce59d900fa4173482085eeca44bfe864336534a /Doc/library/string.rst
parente0b23095ee03a11d09f38cbc689307dc5c93afda (diff)
downloadcpython-git-bc1ee460dcbe5811ebb10a6cacd8d3670846f039.tar.gz
Issue #25179: Documentation for formatted string literals aka f-strings
Some of the inspiration and wording is taken from the text of PEP 498 by Eric V. Smith, and the existing str.format() documentation.
Diffstat (limited to 'Doc/library/string.rst')
-rw-r--r--Doc/library/string.rst10
1 files changed, 7 insertions, 3 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst
index 5b917d939b..cda8e8682f 100644
--- a/Doc/library/string.rst
+++ b/Doc/library/string.rst
@@ -188,7 +188,9 @@ Format String Syntax
The :meth:`str.format` method and the :class:`Formatter` class share the same
syntax for format strings (although in the case of :class:`Formatter`,
-subclasses can define their own format string syntax).
+subclasses can define their own format string syntax). The syntax is
+related to that of :ref:`formatted string literals <f-strings>`, but
+there are differences.
Format strings contain "replacement fields" surrounded by curly braces ``{}``.
Anything that is not contained in braces is considered literal text, which is
@@ -283,7 +285,8 @@ Format Specification Mini-Language
"Format specifications" are used within replacement fields contained within a
format string to define how individual values are presented (see
-:ref:`formatstrings`). They can also be passed directly to the built-in
+:ref:`formatstrings` and :ref:`f-strings`).
+They can also be passed directly to the built-in
:func:`format` function. Each formattable type may define how the format
specification is to be interpreted.
@@ -308,7 +311,8 @@ The general form of a *standard format specifier* is:
If a valid *align* value is specified, it can be preceded by a *fill*
character that can be any character and defaults to a space if omitted.
It is not possible to use a literal curly brace ("``{``" or "``}``") as
-the *fill* character when using the :meth:`str.format`
+the *fill* character in a :ref:`formatted string literal
+<f-strings>` or when using the :meth:`str.format`
method. However, it is possible to insert a curly brace
with a nested replacement field. This limitation doesn't
affect the :func:`format` function.