Skip to content

Commit

Permalink
gh-122767: document "new style" formatting for complexes
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Aug 9, 2024
1 parent 2f5c3b0 commit 78a5bf8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Doc/library/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ The meaning of the various alignment options is as follows:
| ``'='`` | Forces the padding to be placed after the sign (if any) |
| | but before the digits. This is used for printing fields |
| | in the form '+000000120'. This alignment option is only |
| | valid for numeric types. It becomes the default for |
| | numbers when '0' immediately precedes the field width. |
| | valid for numeric types, excluding :class:`complex`. |
| | It becomes the default for numbers when '0' immediately |
| | precedes the field width. |
+---------+----------------------------------------------------------+
| ``'^'`` | Forces the field to be centered within the available |
| | space. |
Expand Down Expand Up @@ -432,9 +433,9 @@ including any prefixes, separators, and other formatting characters.
If not specified, then the field width will be determined by the content.

When no explicit alignment is given, preceding the *width* field by a zero
(``'0'``) character enables
sign-aware zero-padding for numeric types. This is equivalent to a *fill*
character of ``'0'`` with an *alignment* type of ``'='``.
(``'0'``) character enables sign-aware zero-padding for numeric types,
excluding :class:`complex`. This is equivalent to a *fill* character of
``'0'`` with an *alignment* type of ``'='``.

.. versionchanged:: 3.10
Preceding the *width* field by ``'0'`` no longer affects the default
Expand Down Expand Up @@ -588,6 +589,14 @@ The available presentation types for :class:`float` and
| | as altered by the other format modifiers. |
+---------+----------------------------------------------------------+

The available presentation types for :class:`complex` are same as for
:class:`float`. Both real and imaginary components of a complex number are
formatted as floating-point numbers, accordingly specified presentaion type.
They separated by mandatory sign of the imaginary part, terminated by ``j``
suffix. If presentation type is missing --- result match the output of
:func:`str` (numbers also surrounded by round parentheses, if real part is
non-zero), altered by other format modifiers.


.. _formatexamples:

Expand Down

0 comments on commit 78a5bf8

Please sign in to comment.