diff options
author | Eric Smith <eric@trueblade.com> | 2010-02-25 14:14:35 +0000 |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2010-02-25 14:14:35 +0000 |
commit | de8b2ac33238122fa680cefe9fd9cc8cdacf0810 (patch) | |
tree | eece66d515fb735aaa0ad4462aa40dd32967a147 | |
parent | e9a78083c0c23fc00b9e20b68288522fe77a22a3 (diff) | |
download | cpython-git-de8b2ac33238122fa680cefe9fd9cc8cdacf0810.tar.gz |
Issue #5965: Add documentation for parts of format specification language.
-rw-r--r-- | Doc/library/string.rst | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 1e4ab73e64..9352666a0c 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -321,8 +321,9 @@ specification is to be interpreted. Most built-in types implement the following options for format specifications, although some of the formatting options are only supported by the numeric types. -A general convention is that an empty format string (``""``) produces the same -result as if you had called :func:`str` on the value. +A general convention is that an empty format string (``""``) produces +the same result as if you had called :func:`str` on the value. A +non-empty format string typically modifies the result. The general form of a *standard format specifier* is: @@ -333,7 +334,7 @@ The general form of a *standard format specifier* is: sign: "+" | "-" | " " width: `integer` precision: `integer` - type: "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "x" | "X" | "%" + type: "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%" The *fill* character can be any character other than '}' (which signifies the end of the field). The presence of a fill character is signaled by the *next* @@ -405,6 +406,17 @@ used from the field content. The *precision* is not allowed for integer values. Finally, the *type* determines how the data should be presented. +The available string presentation types are: + + +---------+----------------------------------------------------------+ + | Type | Meaning | + +=========+==========================================================+ + | ``'s'`` | String format. This is the default type for strings and | + | | may be omitted. | + +---------+----------------------------------------------------------+ + | None | The same as ``'s'``. | + +---------+----------------------------------------------------------+ + The available integer presentation types are: +---------+----------------------------------------------------------+ @@ -432,6 +444,11 @@ The available integer presentation types are: | None | The same as ``'d'``. | +---------+----------------------------------------------------------+ +In addition to the above presentation types, integers can be formatted +with the floating point presentation types listed below (except +``'n'`` and None). When doing so, :func:`float` is used to convert the +integer to a floating point number before formatting. + The available presentation types for floating point and decimal values are: +---------+----------------------------------------------------------+ |