Index: Doc/library/string.rst =================================================================== --- Doc/library/string.rst (revision 78417) +++ Doc/library/string.rst (working copy) @@ -321,8 +321,9 @@ 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 @@ 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,11 +406,22 @@ Finally, the *type* determines how the data should be presented. -The available integer presentation types are: +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 string presentation types are: + + +---------+----------------------------------------------------------+ + | Type | Meaning | + +=========+==========================================================+ | ``'b'`` | Binary format. Outputs the number in base 2. | +---------+----------------------------------------------------------+ | ``'c'`` | Character. Converts the integer to the corresponding | @@ -432,6 +444,11 @@ | None | The same as ``'d'``. | +---------+----------------------------------------------------------+ +In addition to the above presentation types, integers can be formatted +with the floating point presentation types (except ``'n'`` and +None). In that case the :func:`float` function is used to convert the +integer value to a floating point number before formatting. + The available presentation types for floating point and decimal values are: +---------+----------------------------------------------------------+