OLD | NEW |
1 :mod:`string` --- Common string operations | 1 :mod:`string` --- Common string operations |
2 ========================================== | 2 ========================================== |
3 | 3 |
4 .. module:: string | 4 .. module:: string |
5 :synopsis: Common string operations. | 5 :synopsis: Common string operations. |
6 | 6 |
7 **Source code:** :source:`Lib/string.py` | 7 **Source code:** :source:`Lib/string.py` |
8 | 8 |
9 -------------- | 9 -------------- |
10 | 10 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | | ``NAN`` and ``inf`` to ``INF``. | | 444 | | ``NAN`` and ``inf`` to ``INF``. | |
445 +---------+----------------------------------------------------------+ | 445 +---------+----------------------------------------------------------+ |
446 | ``'g'`` | General format. For a given precision ``p >= 1``, | | 446 | ``'g'`` | General format. For a given precision ``p >= 1``, | |
447 | | this rounds the number to ``p`` significant digits and | | 447 | | this rounds the number to ``p`` significant digits and | |
448 | | then formats the result in either fixed-point format | | 448 | | then formats the result in either fixed-point format | |
449 | | or in scientific notation, depending on its magnitude. | | 449 | | or in scientific notation, depending on its magnitude. | |
450 | | | | 450 | | | |
451 | | The precise rules are as follows: suppose that the | | 451 | | The precise rules are as follows: suppose that the | |
452 | | result formatted with presentation type ``'e'`` and | | 452 | | result formatted with presentation type ``'e'`` and | |
453 | | precision ``p-1`` would have exponent ``exp``. Then | | 453 | | precision ``p-1`` would have exponent ``exp``. Then | |
454 | | if ``-4 <= exp < p``, the number is formatted | | 454 | | if ``m <= exp < p`` where ``m`` is -4 for floats and -6 | |
455 | | with presentation type ``'f'`` and precision | | 455 | | for :class:`Decimals <decimal.Decimal>`, the number is | |
| 456 | | formatted with presentation type ``'f'`` and precision | |
456 | | ``p-1-exp``. Otherwise, the number is formatted | | 457 | | ``p-1-exp``. Otherwise, the number is formatted | |
457 | | with presentation type ``'e'`` and precision ``p-1``. | | 458 | | with presentation type ``'e'`` and precision ``p-1``. | |
458 | | In both cases insignificant trailing zeros are removed | | 459 | | In both cases insignificant trailing zeros are removed | |
459 | | from the significand, and the decimal point is also | | 460 | | from the significand, and the decimal point is also | |
460 | | removed if there are no remaining digits following it. | | 461 | | removed if there are no remaining digits following it. | |
461 | | | | 462 | | | |
462 | | Positive and negative infinity, positive and negative | | 463 | | Positive and negative infinity, positive and negative | |
463 | | zero, and nans, are formatted as ``inf``, ``-inf``, | | 464 | | zero, and nans, are formatted as ``inf``, ``-inf``, | |
464 | | ``0``, ``-0`` and ``nan`` respectively, regardless of | | 465 | | ``0``, ``-0`` and ``nan`` respectively, regardless of | |
465 | | the precision. | | 466 | | the precision. | |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 | 756 |
756 .. function:: capwords(s, sep=None) | 757 .. function:: capwords(s, sep=None) |
757 | 758 |
758 Split the argument into words using :meth:`str.split`, capitalize each word | 759 Split the argument into words using :meth:`str.split`, capitalize each word |
759 using :meth:`str.capitalize`, and join the capitalized words using | 760 using :meth:`str.capitalize`, and join the capitalized words using |
760 :meth:`str.join`. If the optional second argument *sep* is absent | 761 :meth:`str.join`. If the optional second argument *sep* is absent |
761 or ``None``, runs of whitespace characters are replaced by a single space | 762 or ``None``, runs of whitespace characters are replaced by a single space |
762 and leading and trailing whitespace are removed, otherwise *sep* is used to | 763 and leading and trailing whitespace are removed, otherwise *sep* is used to |
763 split and join the words. | 764 split and join the words. |
764 | 765 |
OLD | NEW |