summaryrefslogtreecommitdiffstats
path: root/Doc/library/string.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/string.rst')
-rw-r--r--Doc/library/string.rst28
1 files changed, 28 insertions, 0 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst
index 0fec3df..55913f8 100644
--- a/Doc/library/string.rst
+++ b/Doc/library/string.rst
@@ -192,6 +192,15 @@ 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.
+.. index::
+ single: {; in string formatting
+ single: }; in string formatting
+ single: .; in string formatting
+ single: [; in string formatting
+ single: ]; in string formatting
+ single: !; in string formatting
+ single: :; in string formatting
+
Format strings contain "replacement fields" surrounded by curly braces ``{}``.
Anything that is not contained in braces is considered literal text, which is
copied unchanged to the output. If you need to include a brace character in the
@@ -323,6 +332,12 @@ affect the :func:`format` function.
The meaning of the various alignment options is as follows:
+ .. index::
+ single: <; in string formatting
+ single: >; in string formatting
+ single: =; in string formatting
+ single: ^; in string formatting
+
+---------+----------------------------------------------------------+
| Option | Meaning |
+=========+==========================================================+
@@ -349,6 +364,11 @@ meaning in this case.
The *sign* option is only valid for number types, and can be one of the
following:
+ .. index::
+ single: +; in string formatting
+ single: -; in string formatting
+ single: space; in string formatting
+
+---------+----------------------------------------------------------+
| Option | Meaning |
+=========+==========================================================+
@@ -363,6 +383,8 @@ following:
+---------+----------------------------------------------------------+
+.. index:: single: #; in string formatting
+
The ``'#'`` option causes the "alternate form" to be used for the
conversion. The alternate form is defined differently for different
types. This option is only valid for integer, float, complex and
@@ -375,6 +397,8 @@ decimal-point character appears in the result of these conversions
only if a digit follows it. In addition, for ``'g'`` and ``'G'``
conversions, trailing zeros are not removed from the result.
+.. index:: single: ,; in string formatting
+
The ``','`` option signals the use of a comma for a thousands separator.
For a locale aware separator, use the ``'n'`` integer presentation type
instead.
@@ -382,6 +406,8 @@ instead.
.. versionchanged:: 3.1
Added the ``','`` option (see also :pep:`378`).
+.. index:: single: _; in string formatting
+
The ``'_'`` option signals the use of an underscore for a thousands
separator for floating point presentation types and for integer
presentation type ``'d'``. For integer presentation types ``'b'``,
@@ -668,6 +694,8 @@ formatting facilities in Python. As an example of a library built on template
strings for i18n, see the
`flufl.i18n <http://flufli18n.readthedocs.io/en/latest/>`_ package.
+.. index:: single: $; in template strings
+
Template strings support ``$``-based substitutions, using the following rules:
* ``$$`` is an escape; it is replaced with a single ``$``.